본문 바로가기
Python

[네이버] 옥션 검색어를 통한 추천검색어 크롤링(모바일)

by 퍼포먼스마케팅코더 2017. 1. 17.
반응형

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()


      


      

      

            



반응형

댓글