In [1]:
import json
data = """
{
"lastBuildDate": "Sat, 22 Jun 2019 14:57:13 +0900",
"total": 634151,
"start": 1,
"display": 10,
"items": [
{
"title": "MHL 케이블 (아이폰, <b>안드로이드</b> 스마트폰 HDMI TV연결)",
"link": "https://search.shopping.naver.com/gate.nhn?id=10782444869",
"image": "https://shopping-phinf.pstatic.net/main_1078244/10782444869.5.jpg",
"lprice": "16500",
"hprice": "0",
"mallName": "투데이샵",
"productId": "10782444869",
"productType": "2"
},
{
"title": "파인디지털 파인드라이브 Q300",
"link": "https://search.shopping.naver.com/gate.nhn?id=19490416717",
"image": "https://shopping-phinf.pstatic.net/main_1949041/19490416717.20190527115824.jpg",
"lprice": "227050",
"hprice": "359000",
"mallName": "네이버",
"productId": "19490416717",
"productType": "1"
},
{
"title": "주파집 USB NEW 마그네틱 5핀 <b>안드로이드</b> 자석 고속충전케이블",
"link": "https://search.shopping.naver.com/gate.nhn?id=16222651410",
"image": "https://shopping-phinf.pstatic.net/main_1622265/16222651410.20181120154423.jpg",
"lprice": "6500",
"hprice": "11900",
"mallName": "네이버",
"productId": "16222651410",
"productType": "1"
},
{
"title": "MHL 케이블 아이폰 <b>안드로이드</b> HDMI 미러링",
"link": "https://search.shopping.naver.com/gate.nhn?id=11859583359",
"image": "https://shopping-phinf.pstatic.net/main_1185958/11859583359.1.jpg",
"lprice": "12500",
"hprice": "0",
"mallName": "가가넷",
"productId": "11859583359",
"productType": "2"
},
{
"title": "아이폰삼각대 / ios&<b>Android</b> 호환 가능",
"link": "https://search.shopping.naver.com/gate.nhn?id=16341221561",
"image": "https://shopping-phinf.pstatic.net/main_1634122/16341221561.4.jpg",
"lprice": "31900",
"hprice": "0",
"mallName": "포시즌몰",
"productId": "16341221561",
"productType": "2"
},
{
"title": "뷰잉 (viewing)",
"link": "https://search.shopping.naver.com/gate.nhn?id=13030462232",
"image": "https://shopping-phinf.pstatic.net/main_1303046/13030462232.20190306144248.jpg",
"lprice": "87110",
"hprice": "180000",
"mallName": "네이버",
"productId": "13030462232",
"productType": "1"
},
{
"title": "샤오미 Mi Box (TELEBEE)",
"link": "https://search.shopping.naver.com/gate.nhn?id=12302122742",
"image": "https://shopping-phinf.pstatic.net/main_1230212/12302122742.20170920112004.jpg",
"lprice": "54900",
"hprice": "99000",
"mallName": "네이버",
"productId": "12302122742",
"productType": "1"
},
{
"title": "MHL 케이블 아이폰 <b>안드로이드</b> HDMI 미러링 TV연결",
"link": "https://search.shopping.naver.com/gate.nhn?id=8678305242",
"image": "https://shopping-phinf.pstatic.net/main_8678305/8678305242.5.jpg",
"lprice": "5500",
"hprice": "0",
"mallName": "글로벌텐교",
"productId": "8678305242",
"productType": "2"
},
{
"title": "파인디지털 파인드라이브 Q30",
"link": "https://search.shopping.naver.com/gate.nhn?id=18711239261",
"image": "https://shopping-phinf.pstatic.net/main_1871123/18711239261.20190415105108.jpg",
"lprice": "199000",
"hprice": "315640",
"mallName": "네이버",
"productId": "18711239261",
"productType": "1"
},
{
"title": "이노아이오 스마트빔 3",
"link": "https://search.shopping.naver.com/gate.nhn?id=14032821135",
"image": "https://shopping-phinf.pstatic.net/main_1403282/14032821135.20180413144450.jpg",
"lprice": "259870",
"hprice": "387000",
"mallName": "네이버",
"productId": "14032821135",
"productType": "1"
}
]
}
"""
In [4]:
json_data= json.loads(data)
print(json_data['items'][0]['title'])
MHL 케이블 (아이폰, <b>안드로이드</b> 스마트폰 HDMI TV연결)
In [46]:
import requests
client_id = 'dNSXd0_uJvKtGtJKA2Lo'
client_secret = '4qQAz2JMrr'
naver_open_api = 'https://openapi.naver.com/v1/search/shop.json?query=팬텀GT2'
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 index, item in enumerate(data['items']):
print(index+1, item['title'].replace('<b>','').replace('</b>',''), item['link']) #replace로 태그 지우고 출력
else:
print('error code', res.status_code)
1 나이키 팬텀 GT2 엘리트 AG-PRO DC0748-054 https://search.shopping.naver.com/gate.nhn?id=33211198653
2 나이키 팬텀 GT2 엘리트 FG 볼트 크림슨 CZ9890-167 https://search.shopping.naver.com/gate.nhn?id=33065283023
3 나이키 팬텀 GT2 엘리트 FG 축구화 CZ9890-808 https://search.shopping.naver.com/gate.nhn?id=31281924675
4 나이키 팬텀 GT2 아카데미 HG DC0795-054 https://search.shopping.naver.com/gate.nhn?id=32505977989
5 나이키 축구화 팬텀 GT2 인조잔디용 축구 신발 경기화 https://search.shopping.naver.com/gate.nhn?id=84291109102
6 나이키 팬텀 GT2 엘리트 AG-PRO DC0748-808 https://search.shopping.naver.com/gate.nhn?id=31251965390
7 나이키 풋살화 리액트 팬텀 GT2 프로 TF DC0768-054 https://search.shopping.naver.com/gate.nhn?id=33066165716
8 나이키 축구화 팬텀GT2 엘리트 SG 브라이트크림슨 볼트 https://search.shopping.naver.com/gate.nhn?id=30063847944
9 나이키 팬텀 GT2 아카데미 HG 축구화 DC0795-808 https://search.shopping.naver.com/gate.nhn?id=30840421025
10 나이키 코리아정품 팬텀 GT2 엘리트 FG L CZ9890167 CZ9890-167 https://search.shopping.naver.com/gate.nhn?id=33229494792
In [ ]:
import requests
client_id = 'dNSXd0_uJvKtGtJKA2Lo'
client_secret = '4qQAz2JMrr'
naver_open_api = 'https://openapi.naver.com/v1/search/shop.json?query=팬텀GT2'
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 index, item in enumerate(data['items']):
print(index+1, item['title'], item['link'])
else:
print('error code', res.status_code)
In [49]:
import requests
import openpyxl
client_id = 'dNSXd0_uJvKtGtJKA2Lo'
client_secret = '4qQAz2JMrr'
start, num = 1, 0
excel_file = openpyxl.Workbook()
excel_sheet = excel_file.active
excel_sheet.column_dimensions['B'].width = 100
excel_sheet.column_dimensions['C'].width = 100
excel_sheet.append(['랭킹', '제목', '링크'])
for index in range(10):
start_number = start+(index*100)
# 블로그면 blog 기사는 news , 쇼핑은 shop
naver_open_api = 'https://openapi.naver.com/v1/search/news.json?query=쿠쿠렐라&display=100&start=' + str(start_number)
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']:
num += 1
excel_sheet.append([num, item['title'].replace('<b>','').replace('</b>',''), item['link']])
else:
print ("Error Code:", res.status_code)
excel_file.save('cucurella.xlsx')
excel_file.close()
In [45]:
client_id = 'dNSXd0_uJvKtGtJKA2Lo'
client_secret = '4qQAz2JMrr'
star, num =1,0
excel_file =openpyxl.Workbook()
excel_sheet=excel_file.active
excel_sheet.column_dimensions['B'].width=100
excel_sheet.column_dimensions['C'].width=100
excel_sheet.append(['rank','name','link'])
for index in range(10):
start_number=start+ (index*100)
naver_open_api='https://openapi.naver.com/v1/search/shop.json?query=팬텀 GT2&display=100&start=' + str(start_number)
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']:
num+=1
c=excel_sheet.append([num,item['title'], item['link']])
else :
print('error code', res.status_code)
excel_file.save('IT4.xlsx')
excel_file.close()
In [ ]:
'파이썬 활용 > 크롤링' 카테고리의 다른 글
API 크롤링_지역별 산불 통계 _ 학교 수업 때 배운 부분 (0) | 2022.10.25 |
---|---|
크롤링한 데이터 엑셀에 저장 후 불러오기 (0) | 2022.10.24 |
기상 데이터 크롤링(넘파이로 전처리) (0) | 2022.10.24 |
지마켓 탑100개 (품명 ,가격) 크롤링 + 엑셀에 저장 (0) | 2022.10.24 |
크롤링 지마켓- 상품명 + 배송사 크롤링 (0) | 2022.10.24 |