有没有办法使用http.client
模块自动跟踪重定向:
def grab_url(host, path = '/'):
class Data: pass
result = Data()
try:
con = http.client.HTTPConnection(host)
con.request('GET', path)
response = con.getresponse()
if response.status == 200:
result.content = response.read().decode('utf-8')
result.headers = response.getheaders()
catch Exception as e:
print(e)
return result
只要请求返回一个200
的http响应,上述方法就可以工作,但是我不知道如何处理301
之类的重定向?在
使用pyCurl
我只需将FOLLOWLOCATION
设置为True
:
目前没有回答
相关问题 更多 >
编程相关推荐