find_all( ): 원하는 태그들을 리스트 형식으로


from bs4 import BeautifulSoup


html = """<html><head><title>title name</title></head><body><p>test</p></body></html>"""


soup = BeautifulSoup(html, 'lxml')

html_content = soup.find_all('html')

find_p = html_content[0].find_all('body')


print(soup.find_all('원하는 태그 이름'))

print(soup.find_all(id='원하는 id이름'))

print(soup.find_all('원하는 태그이름', class_='클래스이름'))

print(soup.find_all('원하는 태그이름', '클래스이름'))

print(soup.find_all('원하는 태그이름', text='클래스이름'))

print(soup.find_all()) #모든 값

print(soup.find_all(['태그값1','태그값2']) #태그여러개 불러오기



select( ) : CSS 셀렉터를 활용, 리스트로 반환



from bs4 import BeautifulSoup


html = """<html><head><title>title name</title></head><body><p>test</p></body></html>"""


soup = BeautifulSoup(html, 'lxml')

html_content = soup.find_all('html')


print(soup.select('태그'))

print(soup.select('.클래스이름'))

print(soup.select('#아이디이름'))

print(soup.select('태그 태그.클래스'))



'웹 서버 > 크롤러' 카테고리의 다른 글

re활용하기  (0) 2018.05.16
bs4  (0) 2018.05.16
urllib 모듈  (0) 2018.05.15
requests 모듈  (0) 2018.05.15
requests VS urllib  (0) 2018.05.15

+ Recent posts