gpt4 book ai didi

r - base::url 读取网页但 xml2::read_html 给出 404 错误

转载 作者:行者123 更新时间:2023-12-04 12:08:37 24 4
gpt4 key购买 nike

我在使用 rvest 时遇到了一个很奇怪的问题。这是示例之一:https://politics.raisethemoney.com/cchristiansen .此页面可在任何网络浏览器中正常打开,并可通过 base::url 打开。

A connection with                                                              
description "https://politics.raisethemoney.com/cchristiansen"
class "url-libcurl"
mode "r"
text "text"
opened "closed"
can read "yes"
can write "no"

当使用 xml2::read_html 时,会出现 404 错误。

Error in open.connection(x, "rb") : HTTP error 404.

在 Rstudio Cloud 和本地计算机 (Windows 10) 上进行了测试。我很困惑。知道为什么会发生这种情况吗?

最佳答案

服务器正在寻找请求中的特定 header ,即

'Accept' : ''

需要提供此信息以便从服务器向请求提供 200。例如,此 header 是 httr 中的默认 header ,但我假设您在尝试的方法中没有此 header 。

以下是我使用 Python requests(有点类似于 rvest)运行的一些快速测试:

enter image description here

关于r - base::url 读取网页但 xml2::read_html 给出 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58045966/

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