Last active
July 6, 2019 05:58
-
-
Save allieus/69f12e88f28629c8769e38c67d45bff5 to your computer and use it in GitHub Desktop.
실습
This file contains hidden or 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 sys | |
import requests | |
from bs4 import BeautifulSoup | |
def naver_blog_search(q, page=1): | |
url = 'https://search.naver.com/search.naver' | |
params = { | |
'query': q, | |
'where': 'post', | |
'start': (page-1)*10 + 1, | |
} | |
response = requests.get(url, params=params) | |
html = response.text | |
soup = BeautifulSoup(html, 'html.parser') | |
post_list = [] | |
for tag in soup.select('.sh_blog_title'): | |
post_list.append({'url': tag['href'], 'title': tag.text}) | |
return post_list | |
try: | |
keyword = sys.argv[1] | |
post_list = naver_blog_search(keyword) | |
print(post_list) | |
except IndexError: | |
print("Error) 검색어를 입력해주세요.") | |
# 실행 예 : python 네이버_블로그_검색.py 엔드게임 |
This file contains hidden or 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 | |
def get_related_keyword_list(query): | |
url = 'https://search.naver.com/search.naver' | |
params = {'query': query} | |
res = requests.get(url, params=params) | |
soup = BeautifulSoup(res.text, 'html.parser') | |
keyword_list = [tag.text for tag in soup.select('._related_keyword_ul a')] | |
return keyword_list | |
print(get_related_keyword_list('장고')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment