Python

BeautifulSoup으로 크롤링

YoYoHa 2020. 5. 4. 13:52
728x90
반응형
from bs4 import BeautifulSoup

headers = {'User-Agent': 'Mozilla/5.0'}
url = 'Crawling_URL'                  #크롤링 할 페이지 URL

res = requests.get(url,headers=headers)
soup = BeautifulSoup(res.content,'html.parser')

print(soup)


#아래 코드와 같이 해당 URL에서 href주소로 이동 가능
new_url = url+=soup.find('div',class_='ClassName').find('a')['href']
res = requests.get(new_url,headers=headers)
soup = BeautifulSoup(res.content,'html.parser')

print(soup)
728x90
반응형