from bs4 import BeautifulSoup
import urllib.parse
import urllib.request
file = open("C:/Users/eyeden-FF14/Desktop/Auction/food_keywords.txt", 'r' )
Food_keyword_list = open("C:/Users/eyeden-FF14/Desktop/Food_keyword_list.txt", 'w' , encoding='utf-8' )
keywords = file.readlines()
file.close()
Naver_first_URL = 'https://m.search.naver.com/search.naver?query='
Naver_behind_URL = '&where=m&sm=mtp_hty'
#네이버 검색할 URL 만들기
for i in keywords :
a = i.replace("\n", "")
b = str(a)
c = urllib.parse.quote(b) #한글 키워드를 utf-8로 변환
URL = Naver_first_URL + c +Naver_behind_URL
Food_keyword_list.write(URL + '\n')
Food_keyword_list.close()
#추천검색어 ALL 크롤링
import urllib.request
import urllib.parse
from bs4 import BeautifulSoup
file = open("C:/Users/eyeden-FF14/Desktop/Food_keyword_list.txt", 'r' , encoding='utf-8')
outcome = open("C:/Users/eyeden-FF14/Desktop/Food_recommended_keyword_list.txt", 'w', encoding='utf-8')
urls = file.readlines()
for page in urls[0:337] :
url = page.replace("\n", "")
f = urllib.request.urlopen(url)
html = f.read()
bs = BeautifulSoup(html, 'html.parser')
keywords = bs.find_all("a", class_="basic_show")
for i in keywords :
outcome.write(str(i) + '\n')
outcome.close()
'Python' 카테고리의 다른 글
[네이버] 섹션 크롤링3 (0) | 2017.01.18 |
---|---|
[파이썬3] 한글 교정 (0) | 2017.01.17 |
[파이썬3] python txt파일 읽기 에러 'cp949' (0) | 2017.01.17 |
[네이버] 검색어를 통한 섹션 크롤링2 (0) | 2017.01.17 |
[파이썬3] 크롤링할 메모장 파일 읽기 (0) | 2017.01.16 |
댓글