Data Analysis/web crawling
[Crawling] 사이트 분석/ 크롤러 만들기
아이스베어 :)
2021. 6. 8. 16:42
728x90
반응형
사이트 분석
base_url = 'https://pjt3591oo.github.io/'
page_path = '/page%d'
page=2
res = rq.get(base_url)
soup = BeautifulSoup(res.content,'lxml')
posts = soup.select('body main.page-content div.wrapper div.home div.p')
for post in posts:
title = post.find('h3').text.strip()
descript = post.find('h4').text.strip()
author = post.find('span').text.strip()
print(title,descript,author)
base_url = 'https://pjt3591oo.github.io/'
page_path = '/page%d'
page=2
res = rq.get(base_url)
soup = BeautifulSoup(res.content,'lxml')
while True:
sub_path = page_path%(page)
page += 1
res = rq.get(base_url + sub_path) #https://pjt3591oo.github.io/page2/ => page3 이렇게 page 단위로 url 변경하여 크롤링 함
if(res.status_code != 200):
break
soup = BeautifulSoup(res.content,'lxml')
posts = soup.select('body main.page-content div.wrapper div.home div.p')
for post in posts:
title = post.find('h3').text.strip()
descript = post.find('h4').text.strip()
author = post.find('span').text.strip()
print(title,descript,author)
위 페이지 사진을 나타낸것이다.
728x90
반응형