search

Home  >  Q&A  >  body text

python - Problems using requsts.get method?

Please let me know what's wrong with this. I don't see it.

The code is as follows: Is there any problem with the writing method?

import requests

base_url = 'https://xueqiu.com/hq#exchang...';
headers = {'user_agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML , like Gecko) Chrome/53.0.2785.89 Safari/537.36'}

req = requests.request(method='get',url=base_url,headers=headers)
rsp = requests.get(req)

为情所困为情所困2757 days ago752

reply all(3)I'll reply

  • 巴扎黑

    巴扎黑2017-05-18 10:51:47

    Yourreq没有符合url的格式, 看到报错, req的结果是http://<Request[403]>
    刚才去看了requests的模块定义, 觉得requests.requesthas already initiated a visit

    import requests
    
    base_url = 'https://xueqiu.com/hq#exchang...';
    headers = {'user_agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.89 Safari/537.36'}
    
    req = requests.request(method='get',url=base_url,headers=headers)
    
    print req.text # 直接输出

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-05-18 10:51:47

    There seems to be something wrong with the way user_agent in the header is written. It should be written the same way as the browser

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-18 10:51:47

    request.get

    reply
    0
  • Cancelreply