cs/크롤링

[크롤링] 네이버를 시작페이지로

신_이나 2022. 10. 6. 23:48
import requests
from bs4 import BeautifulSoup

#naver 서버에 대화를 시도
response = requests.get("http://www.naver.com")

#naver에서 html 줌
html = response.text

#html parser 으로 soup
soup = BeautifulSoup(html, 'html.parser')

#id 값이 NM_set_home_btn 인 한 개를 찾아냄, # 은 id선택자 (a태그를 가진 id를 선택)
word = soup.select_one("#NM_set_home_btn")

#text 요소만 출력
print(word.text)