search

Home  >  Q&A  >  body text

python requests获取雪球股票信息报错

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: .

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

伊谢尔伦伊谢尔伦2804 days ago1164

reply all(3)I'll reply

  • 高洛峰

    高洛峰2017-04-17 17:49:56

    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

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:49:56

    Visually I guess you’re not logged in

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 17:49:56

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

    reply
    0
  • Cancelreply