-
-
Save kentakang/65c0f7d308b24c73698e476eb4333dcf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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