관리 메뉴

웹개발자의 기지개

[Python] requests 로 json 받을때 동작을 안할때 - 크롤링할때 본문

python

[Python] requests 로 json 받을때 동작을 안할때 - 크롤링할때

웹개발자 워니 2025. 6. 13. 10:49

크롤링시에 

requests 로 json 받아올때 꼭 아래의 header 값을 추가하도록 하자.

CORS 때문에 막혀서 response 결과값을 받을 수가 없다.

 

 

header = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0'}

 

1
2
3
4
5
6
7
8
9
10
11
12
import requests
import datetime
import json
 
header = {'User-Agent''Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0'}
url = "https://production.dataviz.cnn.io/index/fearandgreed/graphdata"
response = requests.get(url,headers=header)
if response.status_code == 200:
    data = response.json()
    print(data)
else:
    print(f"Error: {response.status_code}")
cs

 

 

 

Comments