크롤링 한 로우데이터가 XML 포맷인경우 find_all이나 find 함수를 이용하여 출력한다.
importrequestsfrombs4importBeautifulSoup# XML도 BeautifulSoup 사용
service_key='자신의 서비스 키'params='&numOfRows=10&pageNo=1&sidoName=서울&searchCondition=DAILY'open_api='http://openapi.airkorea.or.kr/openapi/services/rest/ArpltnInforInqireSvc/getCtprvnRltmMesureDnsty?ServiceKey='+service_key+paramsres=requests.get(open_api)soup=BeautifulSoup(res.content,'html.parser')# html.parser 이용
data=soup.find_all('item')# CSS가 아닌 HTML tag이기에 find_all과 find 함수 이용
foritemindata:stationname=item.find('stationname')pm10grade=item.find('pm10grade')print(stationname.get_text(),pm10grade.get_text())
댓글남기기