Beautiful Soup로 찾기
from bs4 import beautifulsoup
find(tag, attributes, recursive, text, keywords)find_all(tag, attributes, recursive, text, limit, keywords)cartoons = soup.find_all('a', attrs={'class':'title'})
#동일한 결과 값 나옴
soup.find('div', {'class' : 'g2b'}).text
soup.find('div', class_ = 'g2b').text
find 함수는 기본적으로 find_all 함수 뿐만 아니라 find_all_previous, find_previous, find_all_next, find_next, find_previous_siblings, find_previous_sibling, find_next_siblings, find_next_sibling, find_parents, find_parent 로 다양하게 지원
select_one : tag 타입으로 결과 값 반환select : list 타입으로 결과 값 반환cartoons = soup.select('a.title')
soup.select('.class명') .은 html 용어로 클래스를 말함soup.select('#id명')soup.select('태그명') html 태그에 아무 것도 안 붙여도 가능 예)
soup.select('Inl#sheet') #Inl이 태그, sheet가 아이디
soup.select('.wala .dodo em')[0].text #wala클래스 안에 있는 dodo 클래스의 태그명 em을 찾아라
#띄어쓰기는 ~안에라는 뜻
soup.find_all('tag')[0].text
== soup.select('tag')[0].text
soup.find_all(class_='name')[0].text
== soup.select('.name')[0].text
soup.find_all(id='name')[0].text
== soup.select('#name')[0].text
.text 텍스트 추출
.get_text 지정 태그를 포함한 모든 하위 태그를 제거하고 텍스트 문자열 반환 (마지막태그에 사용할 것)
Selenium에서 찾기
find_element() 특정 HTML 요소를 찾아서 가져오고 싶을 때 사용한다.
from selenium.webdriver.common.by import By By 클래스는 한 페이지에서 특정한 요소의 위치를 파악하는데 쓰이는데, id/ name/ xpath/ link_Test /tag_name /class_name /css_selector /partial_link_text를 쓸 수 있다.
.text .get_attribute('속성이름') .tag_name