Notice
Recent Posts
Recent Comments
Tags
- simpe ftp
- javascript redirection
- 강제이동
- 404에러페이지
- JavaScript
- javascript 바코드 생성
- asp.net core swagger
- ASP.Net Core 404
- TempData
- django 엑셀불러오기
- asp.net dropdownlist
- 하드 마이그레이션
- SSD 복사
- ViewData
- ViewBag
- asp ftp
- XSS PHP
- swagger 500 error
- 말줄임표시
- XSS방어
- jquery 바코드생성
- 원격ftp
- Mac Oracle
- asp.net core Select
- php 캐쉬제거
- 맥 오라클설치
- 타임피커
- 하드 윈도우 복사
- asp.net Select
- 바코드 생성하기
웹개발자의 기지개
[Python] requests 로 json 받을때 동작을 안할때 - 크롤링할때 본문
크롤링시에
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 |
'python' 카테고리의 다른 글
| [Python] Numpy reshape 함수 설명 (0) | 2025.07.14 |
|---|---|
| [Python] 가상환경이 변경되거나 다른컴에서 가상환경 맞추기 - 가상환경 삭제, 재설치 (0) | 2025.06.15 |
| [Python] 가상환경 생성오류 - Error: Command '['/ai_study/consensus/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1 (0) | 2025.05.27 |
| [Python] Ubuntu 에서 파이썬 버전 여러개 설치 (0) | 2025.05.27 |
| [Python] 특정 웹사이트 크롤링 1 - mysql DB 저장 (0) | 2025.05.26 |
Comments
