본문 바로가기
✨ python/크롤링(Crawling)

파이썬(python) - 크롤링(Crawling) 또는 스크래핑(Scraping) - 2

by 환풍 2023. 5. 11.
728x90

 

http://books.toscrape.com/catalogue/category/books/travel_2/index.html

 

Travel | Books to Scrape - Sandbox

£56.88 In stock

books.toscrape.com

 

 

해당 페이지의 책 제목들을 들고와보자.

 

h

a태그 위의 h3태그로 감싸져있는 것을 볼 수 있다.

 

 

1
2
3
4
5
6
7
from bs4 import BeautifulSoup
from urllib.request import urlopen
html = urlopen('http://books.toscrape.com/catalogue/category/books/travel_2/index.html')
bs = BeautifulSoup(html.read(), 'html.parser')
h3 = spanTagList = bs.find_all('h3')
for h in h3 :
    print(h.get_text())
cs

이러면 끝난다..


 

find_all 을하면 List의 형태로 태그들을 가지고 와준다.

따라서 이렇게 for 문에서 반복시켜주면서 한줄 한줄 데이터를 뽑을 수 있다.

반응형

댓글