Heim > Fragen und Antworten > Hauptteil
import requests
r = requests.get('https://xueqiu.com/stock/forchartk/stocklist.json?symbol=SH600423&period=1day&type=before&end=1463365186825&_=1463365186825')
print r.text
为啥会报 403 Forbidden. Your IP Address: .
应该怎么正确使用能得到返回结果?
高洛峰2017-04-17 17:49:56
需要先访问主页面获取到cookie,再操作
import requests
session = requests.Session()
session.headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
session.get('https://xueqiu.com/')
r = session.get('https://xueqiu.com/stock/forchartk/stocklist.json?symbol=SH600423&period=1day&type=before&end=1463365186825&_=1463365186825')
print r.text