我正在尝试下载以下网站的完整源代码: http://www.carnegiehall.org/Students/
我想要提取的信息如下:
Carnegie Hall介绍
2013年3月28日,星期四|晚上7:30
Lawrence Brownlee
Martin Katz
Zankel Hall
View Source显示该文本的以下代码块:
<div class="info-col">
<div class="up-lic">Carnegie Hall Presents</div>
<div class="date">Thursday, March 28, 2013 | 7:30 PM</div>
<div class="clearfix"></div>
<div class="title color">
<a href="/Calendar/2013/3/28/0730/PM/Lawrence-Brownlee-Martin-Katz/">Lawrence Brownlee<BR>Martin Katz</a>
</div>
<div class="clearfix"></div>
<div class="location"> Zankel Hall</div>
<div class="clearfix"></div>
<br />
在R中运行以下内容时丢失了:
htmlParse(getURL("http://www.carnegiehall.org/Students", .opts = curlOptions(followlocation=TRUE)), asText = TRUE)
谁能告诉我我做错了什么?
答案 0 :(得分:0)
似乎问题只是获取URL(而不是解析它)。您正在寻找的信息不会过来,如下所示:
H <- getURL("http://www.carnegiehall.org/Students", .opts = curlOptions(followlocation=TRUE))
grepl("Zankel Hall", H)
# [1] FALSE
grepl("March 28", H)
# [1] FALSE
如果你仔细观察html,看来日历是通过脚本
加载的答案 1 :(得分:0)
library(XML)
hdata <- htmlParse('http://www.carnegiehall.org/Students/')
xpathSApply(hdata,'//div[@class="info-col"]/div/text()|//div[@class="info-col"]/div/a/text()')
#[[1]]
#Carnegie Hall Presents
#[[2]]
#Thursday, March 28, 2013 | 7:30 PM
#[[3]]
#[[4]]
#Lawrence Brownlee
#[[5]]
#Martin Katz
#[[6]]
# Zankel Hall
#[[7]]