import requests
from bs4 import BeautifulSoup
url = 'http://ncov.mohw.go.kr/bdBoardList_Real.do?brdId=1&brdGubun=11&ncvContSeq=&contSeq=&board_id=&gubun='
res = requests.get(url).text
bs = BeautifulSoup(res, 'html.parser')
# 현재 환자수
now_patient = int((bs.select_one('#content > div > div.caseTable > div:nth-of-type(1) > ul > li:nth-of-type(1) > dl > dd').text).replace(',',''))
NotImplementedError: Only the following pseudo-classes are implemented: nth-of-type.
해결 방법
selenium을 기반으로한 BequtifulSoap에서는 nth-child 선택자를 지원하지 않습니다. nth-child 선택자 대신 nth-of-type 를 사용하면 됩니다.
변경전 | bs.select('#content > div.article > div.section > div.news_area > div > ul > li:nth-child(1) > span > a') |
---|---|
변경후 | bs.select('#content > div.article > div.section > div.news_area > div > ul > li:nth-of-type(1) > span > a') |