Python request.get() 返回 404 页面未找到

标签 python web-scraping python-requests html

我一直有一个有点大的有趣行为,我很想解释为什么会这样。

我正在使用以下内容来抓取一个页面,然后对其进行解析:

r  = requests.get(html)

现在,当我在网页 A 上使用 python 在 Windows 计算机上运行它时,它会像您期望的那样返回页面。

但是,当我在我的 Synology Diskstation(我相信基于 Linux)上运行相同的命令时,它返回一个 404 页面未找到页面而不是输入的 url 页面。

当我尝试不同的 URL 时,它会在两个系统上返回正确的页面。

关于这是如何发生或为什么发生的任何解释?

编辑:我也在家里的 MacBook 上试过,效果很好。但出于某种原因,它仍然无法在 Diskstation 上运行 :S

编辑:

来自两台机器的 header

Mac(它工作的地方):

{'Content-Length': '17924', 'X-Content-Type-Options': 'nosniff', 'Content-Encoding': 'gzip', 'Set-Cookie': 'PHPSESSID=q86c56e1e4t1d8jsu0penc488oraladt; path=/', 'Vary': 'Host,Accept-Encoding', 'Keep-Alive': 'timeout=10, max=100', 'Server': 'Apache', 'Connection': 'Keep-Alive', 'Date': 'Tue, 24 Jan 2017 04:31:08 GMT', 'Content-Type': 'text/html'}

Diskstation(没有的地方):

{'X-Content-Type-Options': 'nosniff', 'Transfer-Encoding': 'chunked', 'Vary': 'Host', 'Keep-Alive': 'timeout=10, max=100', 'Server': 'Apache', 'Connection': 'Keep-Alive', 'Date': 'Tue, 24 Jan 2017 04:30:25 GMT', 'Content-Type': 'text/html'}

最佳答案

很可能是您遇到了 robots.txt 问题,或者两个系统之间发送的 header 信息不同。基本跟踪应该为您指明正确的方向。

关于Python request.get() 返回 404 页面未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41816669/

相关文章:

python - 如何将多个列值连接到 Pandas 数据框中的单个列

ruby-on-rails - Mechanize ruby无法看到linkedin中的所有内容

python - 即使页面存在,为什么我在 python 请求中收到 404 错误?

python - 为 Kivy-ios 编译自定义模块

python - 遍历Python中的列表列表

python - 通过 pod 访问 kubernetes python api

Python str View

python - 无法在 Scrapy 项目中使用代理

python - 在 Python 中使用 Selenium 抓取 JavaScript 呈现的内容

python - 使用 requests 登录后获取受限页面,urllib2 python