XML 특정 요소나 속성에 접근키 위한 경로 지정 언어
-
태그 및 속성 선택
1
2
3crawling_data = soup.find('h1') crawling_data = soup.find(id='title') crawling_data = soup.find('p', class_='cssstyle') crawling_data = soup.find('p', attrs = {'align': 'center'})
-
CSS Selector
1
2
3
4crawling_data = soup.select('html > title') crawling_data = soup.select('div.article_view') crawling_data = soup.select('#harmonyContainer') crawling_data = soup.select('div#mArticle div#harmonyContainer')
-
XPath
-
bs 미지원 / Selenium or PhantomJS 지원
1
2
3
4
5
6
7
8
9
10
11# 문서 내 태그 검색 title = driver.find_element_by_xpath("//title") # 절대 경로 title = driver.find_element_by_xpath("/html/head/title") # html 태그 내 검색 title = driver.find_element_by_xpath("/html//title") # soup.find('h3', attrs = {'class' : 'tit_s'}) title_content = driver.find_element_by_xpath("//h3[@class='tit_view']")
-