request.get(url) 返回空内容 [英] request.get(url) returns empty content
本文介绍了request.get(url) 返回空内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试解决这个问题,但没有运气:
I am trying to figure this out, but had no luck:
import requests
r = requests.get('http://example.com/m7ppct4', allow_redirects=True)
r.status_code
返回 200
,r.content
返回 ''
.
r.headers
返回以下字典:
{'content-length': '0',
'content-language': 'en-US',
'x-powered-by': 'Servlet/3.0',
'set-cookie': '__cfduid=d4b3d47d43189ac72be14b1d2a2bed98a1408989649815; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.azdoa.gov; HttpOnly, LWJSESSIONID=0000SESSIONMANAGEMENTAFFINI:18h1v85u3; Path=/; HttpOnly, NSC_batubufkpctWTTTM=ffffffff09f39f1545525d5f4f58455e445a4a42378b;expires=Mon, 25-Aug-2014 18:02:49 GMT;path=/;secure;httponly',
'expires': 'Thu, 01 Dec 1994 16:00:00 GMT',
'server': 'cloudflare-nginx',
'connection': 'keep-alive',
'x-ua-compatible': 'IE=EmulateIE9',
'cache-control': 'no-cache="set-cookie, set-cookie2"',
'date': 'Mon, 25 Aug 2014 18:00:49 GMT',
'cf-ray': '15f9b0ff50cf0d6d-LAX',
'content-type': 'application/octet-stream'}
当我在浏览器中打开页面时,我清楚地看到了内容.
When I open the page in a browser, I clearly get content.
对如何进行调试有任何想法吗?我想通过 requests.get()
调用获取页面内容.
Any thoughts on how I can proceed debugging this? I would like to get the page content with a requests.get()
call.
推荐答案
您必须发送任何用户代理:
You must send any user agent:
import requests
r = requests.get('http://example.com/m7ppct4', headers={'User-Agent':'test'})
这篇关于request.get(url) 返回空内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文