我在这里看到了类似的问题并实施了解决方案,但似乎仍然无法解决这个问题。还是一个 R 新手,所以请耐心等待:我已经设法使用 rvest从该网站获取了巴拉克·奥巴马 (Barack Obama) 的演讲表:
library(rvest)
page <- read_html("http://www.americanrhetoric.com/barackobamaspeeches.htm")
speeches <- page %>%
html_nodes(xpath = '//*[@id="AutoNumber1"]') %>%
html_table(fill=TRUE)
speeches <- speeches[[1]][,2:4]
head(speeches)
Run Code Online (Sandbox Code Playgroud)
产生:
X2 X3 X4
1 <NA> <NA> <NA>
2 Delivery Date Speech Title/Text/MultiMedia Audio
3 27 July 2004 Democratic National Convention Keynote Speech mp3
4 06 January 2005 Senate Speech on Ohio Electoral Vote Counting mp3
5 04 June 2005 Knox College Commencement Speech mp3
6 15 December 2005 Senate Speech on the PATRIOT Act …Run Code Online (Sandbox Code Playgroud) 我正在学习如何进行网页抓取rvest,但遇到了一些问题。具体来说,代码仅拾取标题行。
library(rvest)
library(XML)
URL1 <- "https://swishanalytics.com/optimus/nba/daily-fantasy-salary-changes?date=2017-11-25"
df <- URL1 %>% read_html() %>% html_node("#stat-table") %>% html_table()
Run Code Online (Sandbox Code Playgroud)
调用df结果为 7 列 0 行的 data.frame。我安装了检查器小工具,即使这样也告诉我这id = #stat-table是正确的。该网站的独特之处在于它不想获取表格数据?
作为一个单独的问题,如果我“查看页面源代码”,我可以看到页面上的所有数据,并且我不必用来RSelenium翻阅 DK、FD 或 yahoo 工资。看起来有些键很容易找到(例如查找“FD”>查找所有“玩家名称:”并在后面拾取字符等),但我不知道处理该页面的库/进程来源。有这方面的资源吗?
谢谢。
我正在尝试从以下链接中抓取滚动表:http : //proximityone.com/cd114_2013_2014.htm
我正在使用 rvest,但无法为表格找到正确的 xpath。我目前的代码如下:
url <- "http://proximityone.com/cd114_2013_2014.htm"
table <- gis_data_html %>%
html_node(xpath = '//span') %>%
html_table()
Run Code Online (Sandbox Code Playgroud)
目前我收到错误“没有适用于 'html_table' 的方法应用于类“xml_missing”的对象”
任何人都知道我需要更改什么才能抓取链接中的交互式表格?
我正在尝试提取类似于以下内容的表的所有链接:
<!DOCTYPE html>
<html>
<body>
<table>
<tr>
<td>
<a href="https://www.r-project.org/">R</a><br>
<a href="https://www.rstudio.com/">RStudio</a>
</td>
</tr>
<tr>
<td>
<a href="https://community.rstudio.com/">Rstudio Community</a>
</td>
</tr>
</table>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我想做的是在末尾获取一个数据帧(或向量)列表,其中每个数据帧包含 html 表中每一行的所有链接。例如,在这种情况下,列表将具有向量 1 c("https://www.r-project.org/","https://www.rstudio.com/"),第二个向量将为c("https://community.rstudio.com/")。我现在遇到的主要问题是,当我执行以下操作时,我无法保留与每个节点的 href 关系:
library(rvest)
web <- read_html("table.html") %>%
html_nodes("table") %>%
html_nodes("tr") %>%
html_nodes("a") %>%
html_attr("href")
Run Code Online (Sandbox Code Playgroud) 我想使用 rvest 包中的 download.file 来下载 pdf。链接如下。 https://www4.stat.ncsu.edu/~reich/ABA/Derivations3.pdf
我的代码是
download.file("https://www4.stat.ncsu.edu/~reich/ABA/Derivations3.pdf",destfile = "d3.pdf")
Run Code Online (Sandbox Code Playgroud)
它确实下载了一个 1.7mb 的 pdf 文件,但当我打开它时,它是空白的。我尝试下载的其他 pdf 文件出现错误消息,指出该文件已损坏。
为什么download.file命令无法下载pdf文件?
我想在 R 中抓取以下页面的内容:http : //directoriosancionados.funcionpublica.gob.mx/SanFicTec/jsp/Ficha_Tecnica/SancionadosN.htm
但是,我找不到任何可以帮助我获取信息的 HTML 标记或任何其他工具。
我有兴趣使用“INHABILITADOS Y MULTADOS”部分的信息构建一个数据框,如下图所示:
选择此选项后,会出现一个包含多个提供程序的菜单,每个提供程序都有一个特定的表格,其中包含我想要回忆的信息。
我是网络抓取的新手,我想获取此网页的数据:http : //www.neotroptree.info/data/countrysearch
在此链接中,我们看到四个字段(国家、域、州和站点)。
我有一个包含站点名称的数据框,我使用以下代码对其进行了抓取:
ipak <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}
ipak(c("rgdal", "tidyverse"))
#> Loading required package: rgdal
#> Loading required package: sp
#> rgdal: version: 1.3-4, (SVN revision 766)
#> Geospatial Data Abstraction Library extensions to R successfully loaded
#> Loaded GDAL runtime: GDAL 2.2.2, released 2017/09/15
#> Path to GDAL shared files: /usr/share/gdal/2.2
#> GDAL binary built with GEOS: TRUE
#> Loaded …Run Code Online (Sandbox Code Playgroud) 我一直在尝试使用来自Pitchfork https://pitchfork.com/reviews/albums/us-girls-heavy-light/ 的rvest in r 来显示这首歌的评论评级。在这种情况下,它是 8.5。但不知何故我得到了这个:

这是我的代码
library(rvest)
library(dplyr)
library(RCurl)
library(tidyverse)
URL="https://pitchfork.com/reviews/albums/us-girls-heavy-light/"
webpage = read_html(URL)
cat("Review Rating")
webpage%>%
html_nodes("div span")%>%
html_text
Run Code Online (Sandbox Code Playgroud) 之前抓取过网页,现在返回403 Forbidden 错误。当我通过浏览器手动访问该网站时,没有任何问题,但是当我现在抓取页面时,我收到错误。
代码是:
url <- 'https://www.punters.com.au/form-guide/'
download.file(url, destfile = "webpage.html", quiet=TRUE)
html <- read_html("webpage.html")
Run Code Online (Sandbox Code Playgroud)
错误是:
Error in download.file(url, destfile = "webpage.html", quiet = TRUE) :
cannot open URL 'https://www.punters.com.au/form-guide/'
In addition: Warning message:
In download.file(url, destfile = "webpage.html", quiet = TRUE) :
cannot open URL 'https://www.punters.com.au/form-guide/': HTTP status was '403 Forbidden'
Run Code Online (Sandbox Code Playgroud)
我查看了文档并尝试在网上寻找答案,但到目前为止还没有运气。有什么建议我可以如何规避这个问题吗?
我正在尝试从以下网页下载一份 Word 文档。当您按下按钮时,Word文档将自动下载,而不显示任何下载链接。
现在我正在尝试使用 XPath,在 R 中下载此文档。
library(rvest)
# send an HTTP GET request to the URL
url <- "https://ec.europa.eu/taxation_customs/tedb/taxDetails.html?id=4205/1672527600"
page <- read_html(url)
# locate the link to the Word document using CSS selector
doc_link <- page %>%
html_nodes(xpath='//*[@id="action_word_export"]')%>%
html_attr("href")
Run Code Online (Sandbox Code Playgroud)
但不幸的是,这不起作用,并且无法下载任何内容。那么有人可以帮助如何解决这个问题并在R环境中下载Word文档吗?