본문 바로가기

python

파이썬 beautifulsoup함수 정리

findAll() 이나 find() ☞ 함수를 쓰면 html 페이지에서 원하는 두 함수는 거의 비슷하다.

findAll(tag, attributes, recursive, text, limit, keywords)

find(tag, attributes, recursive, text, keywords)

findAll( ) ☞ html 태그에서 반복되는 태그를 찾아 처리할 때 효과적이다.

for div in soup.findAll('div', {'class': 'product_tile'}):

p_tag = div.find('a', {'class': 'product_name desktop_content tablet_content'}).getText()
name_tag = div.find('div', {'class': 'product_subtitle'}).getText()
span_tag = div.find('p', {'class': 'product_price price_sale b-product_price-sale b-product_price'}).getText()
img_tag = div.find('img')

print(p_tag.strip())
print(name_tag.strip())
print(span_tag.strip())
print(img_tag.get('data-desktop-src').strip())