我对程序进行了多次调试以获得如下结果:
url 研究所知识库列表
/handle/1471x/1 力学研究所
/handle/1471x/8865 半导体研究所但是,没有元参数我使用,结果是不正确的。表中的内容是我进一步分析的基础之一,我对此感到非常不安。我期待着您真诚的帮助。
## download community-list ---the 1st level of IR Grid
#loading webpage and analyzing
community_url<-"http://www.irgrid.ac.cn/community-list"
com_source <- readLines(community_url, encoding = "UTF-8")
com_parsed <- htmlTreeParse(com_source, encoding = "UTF-8", useInternalNodes = TRUE)
# get table specs
tableNodes <- getNodeSet(com_parsed, "//table")
com_tb<-readHTMLTable(tableNodes[[8]], header=TRUE)
# get External links
xpath <- "//a/@href"
getHTMLExternalFiles(tableNodes[[8]], xpQuery = xpath)发布于 2016-05-25 13:09:38
目前还不清楚您希望最终结果是什么样子,但是如果您稍微修改xpath语句以利用DOM结构,您可以得到如下内容:
library(XML)
community_url<-"http://www.irgrid.ac.cn/community-list"
com_source <- readLines(community_url, encoding = "UTF-8")
com_parsed <- htmlTreeParse(com_source, encoding = "UTF-8", useInternalNodes = TRUE)
list_header <- xpathSApply(com_parsed, '//table[.//li]//h1', xmlValue)
hrefs <- xpathSApply(com_parsed, '//li[@class="communityLink"]//@href', function(x) unname(x))
display_text <- xpathSApply(com_parsed, '//li[@class="communityLink"]//a', xmlValue)
table_data <- cbind(display_text, hrefs)
colnames(table_data) <- c(list_header, "url")
table_data控制台输出导致堆栈溢出,认为这个答案是垃圾邮件,但这里有一个屏幕截图:

https://stackoverflow.com/questions/37436544
复制相似问题