본문 바로가기
Python

BeautifulSoup으로 크롤링

by YoYoHa 2020. 5. 4.
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
반응형

'Python' 카테고리의 다른 글

Python 에서 MySQL 데이터 가져오기  (2) 2020.05.04
숫자 판별함수  (0) 2020.05.04

댓글