gpt4 book ai didi

python - request.get(url) 返回空内容

转载 作者:太空宇宙 更新时间:2023-11-03 12:17:17 26 4
gpt4 key购买 nike

我正在尝试解决这个问题,但运气不佳:

import requests
r = requests.get('http://example.com/m7ppct4', allow_redirects=True)

r.status_code 返回 200r.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'}

当我在浏览器中打开页面时,我清楚地看到了内容。

关于如何继续调试这个的任何想法?我想通过 requests.get() 调用获取页面内容。

最佳答案

看起来由 tinyurl (azstatejobs) 链接的网站会根据用户代理过滤请求。欺骗 Chrome 用户代理对我有用:

import requests
url = 'http://tinyurl.com/m7ppct4'
user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36'
headers = {'User-Agent': user_agent}
r = requests.get(url, headers=headers)

(allow_redirect 默认为真)

您可能想尝试不同的用户代理,看看是什么让该网站不像 python 请求用户代理。

关于python - request.get(url) 返回空内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25491872/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com