Shopping에서 iphone 검색 순위 1000개 가져오기
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 34 35 36 37 38 39 40 41  | import requestsimport pprintimport openpyxlclient_id ='XiNJxT192mk123'client_secret = 'dpolse'excel_file = openpyxl.Workbook()excel_sheet = excel_file.activeexcel_sheet.column_dimensions['B'].width = 100excel_sheet.column_dimensions['C'].width = 100excel_sheet.append(['rank','title','link'])#100개의 결과 가져오기 , display는 최대 100으로 지정가능하므로 start 위치를 변경시켜 반복 한다start_num, item_index = 1, 1for index in range(10):    start_num =  1+index*100         naver_open_api = 'https://openapi.naver.com/v1/search/shop.json?query=iphone&display=100&sort=sim&start='         naver_open_api = naver_open_api + str(start_num)    #print(naver_open_api)        header_params = {'X-Naver-Client-Id':client_id ,'X-Naver-Client-Secret':client_secret}    res = requests.get(naver_open_api, headers=header_params)    if res.status_code == 200:        data = res.json()        for item in data['items']:            #print(item_index, item['title'],item['link'])            excel_sheet.append([item_index, item['title'], item['link']])            item_index += 1    else:        print("Error code : ",res.status_code)                  excel_file.save('shpping_1000.xlsx')excel_file.close() | 
'python' 카테고리의 다른 글
| 크롤링 연습 10. session을 이용한 post 예제 (0) | 2019.12.26 | 
|---|---|
| 크롤링 연습 9. 공공데이터 ex)미세먼지 (0) | 2019.12.26 | 
| 크롤링 연습 7. open API test (0) | 2019.12.26 | 
| 크롤링 연습 6. openpyxl 이용 웹 데이터 저장 (0) | 2019.12.25 | 
| 크롤링 연습 5. urllib 사용 및 게시판 글 리스트 모두 가져오기 (0) | 2019.12.25 |