Skip to content

Instantly share code, notes, and snippets.

@kentakang
Last active July 19, 2018 05:11
Show Gist options
  • Save kentakang/65c0f7d308b24c73698e476eb4333dcf to your computer and use it in GitHub Desktop.
Save kentakang/65c0f7d308b24c73698e476eb4333dcf to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup
import pymysql
import datetime
conn = pymysql.connect(host='localhost', user='root', password='', db='', charset='utf8')
curs = conn.cursor()
sql = "INSERT INTO search(first, second, third, fourth, fifth, sixth, seventh, eighth, ninth, tenth, date) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
html = requests.get('https://www.naver.com/').text
soup = BeautifulSoup(html, 'html.parser')
title_list = soup.select('.PM_CL_realtimeKeyword_rolling span[class*=ah_k]')
curs.execute(sql, (title_list[0].text, title_list[1].text, title_list[2].text, title_list[3].text, title_list[4].text, title_list[5].text, title_list[6].text,
title_list[7].text, title_list[8].text, title_list[9].text, datetime.datetime.now()))
conn.commit()
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment