【问题标题】:Scraping html with rvest - getting http error 416使用 rvest 抓取 html - 获取 http 错误 416
【发布时间】:2015-09-14 13:02:55
【问题描述】:

我正在尝试使用 R(包 rvest)抓取此页面的 HTML,但收到“客户端错误 416:请求的范围不满足”

经过长时间的搜索,我似乎找不到解决方案。尝试使用解析 HTML 页面的 rvest 的 html 函数时会抛出错误:

url <- "http://shop.tcgplayer.com/magic/onslaught/polluted-delta"
html(url)

我使用的是 R 版本 3.2.0。

任何帮助将不胜感激!

【问题讨论】:

  • 使用devtools::install_github("hadley/rvest")github 安装新版本,它应该可以工作。 html 现在是 read_html
  • 感谢您的回复@user227710。 read_html 工作没有错误,但它只返回 2 行,他们让我认为网站阻止了抓取:[1] &lt;head&gt;\n&lt;meta name="ROBOTS" content="NOINDEX, NOFOLLOW"/&gt;\n&lt;meta http-equiv="cache-control" cont ... [2] &lt;body&gt;\n&lt;div id="distil_ident_block"&gt;Â &lt;/div&gt;\n&lt;/body&gt;
  • read_html 现在只提供 2 行输出(默认情况下)。

标签: html r scrape rvest


【解决方案1】:

您已经很接近了,只需使用现在更新的read_html 继续从url 中提取:

> read_html(url) %>%
+   html_nodes("table") %>%
+   html_text() %>%
+   .[[1]]
[1] "\r\n                                Rarity:\r\n                                                R\r\n                                                Card Type:\r\n                                                Land \r\n                                                Description:\r\n                                                Tap, Pay 1 life, Sacrifice Polluted Delta:  Search your library for an island or swamp card   and put it into play. Then shuffle your library.\r\n\r\n                                \r\n                        "

【讨论】:

    猜你喜欢
    • 2019-11-14
    • 1970-01-01
    • 2020-01-10
    • 2018-03-13
    • 1970-01-01
    • 2020-04-19
    • 1970-01-01
    • 2023-03-21
    • 2022-01-15
    相关资源
    最近更新 更多