http 요청 보낼 때 사용
import requests
res = requests.get("https://www.naver.com/")
htmlCode = res.text
requests로 받아온 html 코드는 그냥 문자열이기 때문에 파싱하기가 어려워서 이를 수프로 만들어줘야 한다.
import requests
from bs4 import BeautifulSoup
res = requests.get("https://www.naver.com/")
htmlCode = res.text
# html parser로 수프를 만든다.
soup = BeautifulSoup(htmlCode, 'html.parser')
# 아이디가 NM_set_home_btn인 태그 선택
w = soup.select_one("#NM_set_home_btn") # select함수로 태그 여개 선택할 수도 있음
print(w)
# => <a class="link_set" data-clk="top.mkhome" href="https://help.naver.com/support/welcomePage/guide.help" id="NM_set_home_btn">네이버를 시작페이지로</a>
print(w.text)
# => 네이버를 시작페이지로