파이썬 크롤링 기본

BABY CAT·2022년 8월 9일
0

python

목록 보기
2/22
!pip install requests
import requests
from bs4 import BeautifulSoup
header = { 'User-agent':'Mozila/2.0'} # ai/매크로가 아닌 것처럼
# naver서버에대화시도
response = requests.get('https://www.naver.com/', headers = header) 
# naver에서 html 을 응답으로 줌
html = response.text
#html 번역선생님으로수프만듦
soup = BeautifulSoup(html, 'html.parser')
# < 보라색 주황색 = "파랑색" >
#   태그명 속성명    속성값
#   div    vlass    "hdline"
titles = soup.select('.lnk_hdline_article')
# print(titles.text.strip())
for title in titles:
    print(title.text.strip())

0개의 댓글