python requests获取雪球股票信息报错
伊谢尔伦
伊谢尔伦 2017-04-17 17:47:56
0
3
1167
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: .

应该怎么正确使用能得到返回结果?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(3)
小葫芦

You need to visit the main page to get the cookie first, and then operate

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
Ty80

Visually I guess you’re not logged in

巴扎黑

Try adding user agent. It is also possible that the crawling frequency is too fast and the IP is blocked.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template