1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #공공 open API 테스트 #xml 포멧 활용 # 역시 bs4를 이용하여 xml 데이터를 가져온다. import requests from bs4 import BeautifulSoup service_key = '?ServiceKey=abcd' open_api = 'http://openapi.airkorea.or.kr/openapi/services/rest/ArpltnInforInqireSvc/getCtprvnMesureSidoLIst' params = '&numOfRows=10&pageNo=1&sidoName=서울&searchCondition=DAILY' url = open_api + service_key + params #print(url) #요청 res = requests.get(url) soup = BeautifulSoup(res.content, 'html.parser' ) data = soup.find_all( 'item' ) #요청에 대한 결과 처리 if res.status_code == 200 : for item in data: #print(item.get_text()) #print(item) cityname = item.find( 'cityname' ) pm10value = item.find( 'pm10value' ) print(cityname.get_text(), pm10value.get_text()) else : print( "Error code : " ,res.status_code) |
'python' 카테고리의 다른 글
자주 쓰는 string 함수 (0) | 2019.12.26 |
---|---|
크롤링 연습 10. session을 이용한 post 예제 (0) | 2019.12.26 |
크롤링 연습 8. Open API사용한 report 작성 (0) | 2019.12.26 |
크롤링 연습 7. open API test (0) | 2019.12.26 |
크롤링 연습 6. openpyxl 이용 웹 데이터 저장 (0) | 2019.12.25 |