【问题标题】:Error when getting value from a php file with requests从带有请求的 php 文件中获取值时出错
【发布时间】:2022-01-14 16:58:10
【问题描述】:

我使用 requests 库从网站获取数据,但使用 .get 时会返回错误页面。

import requests
ul = "https://botboy1.000webhostapp.com/gen.php"
hd = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"}


got = requests.get(ul, headers=hd, verify=False)
print(got.text)

如果您访问该网站,它会显示“botboy 是最好的网站”,但如果您使用 .get,它会返回一个 iframe,从而导致错误页面。 提前致谢

【问题讨论】:

  • 我刚刚运行了这个脚本,它打印出botboy is the best website。我认为它有效

标签: python python-3.x python-requests


【解决方案1】:

您的代码似乎对我有用。我在 Windows 10 下运行 Py3.8.10,请求为 2.26.0。 确保您拥有最新版本的请求。你可以更新它:

pip install --upgrade requests

我觉得少了点什么。尝试运行以下显示您正在使用的 Python 和 Requests 版本的代码,以防您安装了多个版本并且没有使用您认为的版本。

import requests, sys

print(sys.version_info[:3], requests.__version__)

ul = "https://botboy1.000webhostapp.com/gen.php"
hd = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36"}

got = requests.get(ul, headers=hd, verify=False)
print(got.text)

【讨论】:

  • 我也在使用 2.26.0 和 python 版本 3.9.4 但我得到
  • 你在什么平台上?我刚刚在 Windows 上使用 Py3.9.4 重新运行,它再次运行良好。我确实收到了警告,但它运行正常。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-01-13
  • 1970-01-01
  • 1970-01-01
  • 2019-08-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多