python - Problems using requsts.get method?
为情所困
为情所困 2017-05-18 10:49:47
0
3
783

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)

为情所困
为情所困

reply all(3)
巴扎黑

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 # 直接输出
淡淡烟草味

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

Peter_Zhu

request.get

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