这篇文章http://www.ajnr.org/content/30/7/1402.full包含四个指向html-tables的链接,我想用rvest来搜索.
借助css选择器:
"#T1 a"
Run Code Online (Sandbox Code Playgroud)
可以像这样到达第一个表:
library("rvest")
html_session("http://www.ajnr.org/content/30/7/1402.full") %>%
follow_link(css="#T1 a") %>%
html_table() %>%
View()
Run Code Online (Sandbox Code Playgroud)
css选择器:
".table-inline li:nth-child(1) a"
Run Code Online (Sandbox Code Playgroud)
可以选择包含链接到四个表的标签的所有四个html节点:
library("rvest")
html("http://www.ajnr.org/content/30/7/1402.full") %>%
html_nodes(css=".table-inline li:nth-child(1) a")
Run Code Online (Sandbox Code Playgroud)
如何循环遍历此列表并一次性检索所有四个表?什么是最好的方法?
我试图从这个站点使用R来刮取数据:http: //www.soccer24.com/kosovo/superliga/results/#
我可以做以下事情:
library(rvest)
doc <- html("http://www.soccer24.com/kosovo/superliga/results/")
Run Code Online (Sandbox Code Playgroud)
但我很难知道如何获取数据.这是因为网站上的实际数据似乎是由Javascript生成的.我能做的是
html_text(doc)
Run Code Online (Sandbox Code Playgroud)
但是这给了很长时间的奇怪文本模糊(这确实包含了数据,但是散布着奇怪的代码,而且根本不清楚我将如何解析它.
我要提取的是所有比赛的比赛数据(日期,时间,球队,结果).此站点不需要其他数据.
任何人都可以提供一些关于如何从该网站提取数据的提示吗?
我正试图从http://google.com抓取内容.错误信息出来了.
library(rvest)
html("http://google.com")
Run Code Online (Sandbox Code Playgroud)
open.connection(x,"rb")出错:
达到了超时此外:
警告消息:不推荐使用'html'.
请改用"read_html".
请参阅帮助("已弃用")
因为我正在使用公司网络,这可能是由防火墙或代理引起的.我尝试使用set_config,但没有工作.
html_nodes()当作为可执行的RScript运行时,该函数失败如下,但在交互式运行时成功.有人知道在跑步中会有什么不同吗?
交互式运行使用全新会话运行,源语句是第一次运行.
$ ./test-pdp.R
>
> ################################################################################
> # Setup
> ################################################################################
> suppressPackageStartupMessages(library(plyr))
> suppressPackageStartupMessages(library(dplyr))
> suppressPackageStartupMessages(library(stringr))
> suppressPackageStartupMessages(library(rvest))
> suppressPackageStartupMessages(library(httr))
>
>
> read_html("http://google.com") %>%
+ html_nodes("div") %>%
+ length()
Error in as.vector(x, "list") :
cannot coerce type 'environment' to vector of type 'list'
Calls: %>% ... <Anonymous> -> lapply -> as.list -> as.list.default
Execution halted
Run Code Online (Sandbox Code Playgroud)
然而,当以source()交互方式运行时它会成功:
> source("/Users/a6001389/Documents/projects/hottest-deals-page-scrape/src/test-pdp.R", echo=TRUE)
> #!/usr/bin/RScript
> options(echo=TRUE)
> ################################################################################
> # Setup
> ####################################################### .... [TRUNCATED]
> suppressPackageStartupMessages(library(dplyr)) …Run Code Online (Sandbox Code Playgroud) 使用R中的rvest来抓取网页,我想从节点中提取相应的内容innerHTML,特别是在应用之前将换行符更改为换行符html_text.
所需功能的示例:
library(rvest)
doc <- read_html('<html><p class="pp">First Line<br />Second Line</p>')
innerHTML(doc, ".pp")
Run Code Online (Sandbox Code Playgroud)
应产生以下输出:
[1] "<p class=\"pp\">First Line<br>Second Line</p>"
Run Code Online (Sandbox Code Playgroud)
有了rvest 0.2这个就可以实现toString.XMLNode
# run under rvest 0.2
library(XML)
html('<html><p class="pp">First Line<br />Second Line</p>') %>%
html_node(".pp") %>%
toString.XMLNode
[1] "<p class=\"pp\">First Line<br>Second Line</p>"
Run Code Online (Sandbox Code Playgroud)
随着更新,rvest 0.2.0.900这不再起作用.
# run under rvest 0.2.0.900
library(XML)
html_node(doc,".pp") %>%
toString.XMLNode
[1] "{xml_node}\n<p>\n[1] <br/>"
Run Code Online (Sandbox Code Playgroud)
所需的功能通常在write_xml包的功能中可用xml2,rvest现在取决于 - 如果只能write_xml将其输出提供给变量而不是坚持写入文件.(也是textConnection不接受的). …
我需要为R版本3.1.2安装rvest包(2014-10-31)
我收到这些错误:
checking whether the C++ compiler supports the long long type... no
*** stringi cannot be built. Upgrade your C++ compiler's settings
ERROR: configuration failed for package ‘stringi’
* removing ‘/usr/local/lib64/R/library/stringi’
ERROR: dependency ‘stringi’ is not available for package ‘stringr’
* removing ‘/usr/local/lib64/R/library/stringr’
ERROR: dependency ‘stringr’ is not available for package ‘httr’
* removing ‘/usr/local/lib64/R/library/httr’
ERROR: dependency ‘stringr’ is not available for package ‘selectr’
* removing ‘/usr/local/lib64/R/library/selectr’
ERROR: dependencies ‘httr’, ‘selectr’ are not available for package ‘rvest’
* removing …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用rvest包来从网页中抓取数据.在一个简单的格式中,html代码如下所示:
<div class="style">
<input id="a" value="123">
<input id="b">
</div>
Run Code Online (Sandbox Code Playgroud)
我想从第一个输入中获取值123.我尝试了以下R代码:
library(rvest)
url<-"xxx"
output<-html_nodes(url, ".style input")
Run Code Online (Sandbox Code Playgroud)
这将返回一个输入标签列表:
[[1]]
<input id="a" value="123">
[[2]]
<input id="b">
Run Code Online (Sandbox Code Playgroud)
接下来我尝试使用html_node通过id引用第一个输入标记:
html_node(output, "#a")
Run Code Online (Sandbox Code Playgroud)
这里它返回了一个空值列表,而不是我想要的输入标签.
[[1]]
NULL
[[2]]
NULL
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何使用其id引用输入标记?
我想找到下面网页中使用的所有课程.这是否可能与rvest或我还需要一些正则表达式/ grepl?一旦我知道了类的名称,我就能够抓取信息,但是对于具有动态构建的类名的页面,可以方便地概述所使用的类.
library(rvest)
doc_url<-"http://curia.europa.eu/juris/document/document.jsf?text=&docid=160583&pageIndex=0&doclang=fr&mode=req&dir=&occ=first&part=1&cid=676771"
page<-read_html(doc_url)
language<- page%>%html_nodes(".C49FootnoteLangue")%>%html_text()
Run Code Online (Sandbox Code Playgroud) 使用以下文档我一直试图从marketwatch.com刮掉一系列表
这是代码所代表的代码:
链接和xpath已包含在代码中:
url <- "http://www.marketwatch.com/investing/stock/IRS/profile"
valuation <- url %>%
html() %>%
html_nodes(xpath='//*[@id="maincontent"]/div[2]/div[1]') %>%
html_table()
valuation <- valuation[[1]]
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Warning message:
'html' is deprecated.
Use 'read_html' instead.
See help("Deprecated")
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我是rvest的新手,我正在尝试确定是否可以使用rvest单击激活div的选项卡以便可以删除数据.我一直在阅读关于cran 的rvest文档,并且没有阅读任何关于点击链接,按钮或标签的内容.
我感兴趣的网站是:touch.tvg.com
从主页我想点击比赛按钮(再次,你如何克服rvest中的按钮)
接下来,我想选择即将到来的比赛.这应该会将我重定向到所选种族的网址.例如:在Hoosier的第10场比赛
一旦成为竞赛页面,我想点击"池"选项卡并抓取池信息.
我在下面附上了一些屏幕截图.任何建议,指导表示赞赏.