I gain a matrix from following program, and trying to extract the specified url from it:
#loading webpage and analyzing
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)
hrefs <- xpathSApply(com_parsed, '//li[@class="communityLink"]//@href', function(x) unname(x))
irname <- xpathSApply(com_parsed, '//li[@class="communityLink"]//a', xmlValue)
cl_table <- cbind(hrefs, irname)
colnames(cl_table) <- c("hrefs", "h1")
I tried url <- cl_table[cl_table$h1=="文献情报中心", ]
and which(cl_table$h1=="文献情报中心")
to do it, but it cause an error:
$ operator is invalid for atomic vectors
and even if it works, I could not get the url of "文献情报中心"(/handle/1471x/23660), how should I do? By the way, is there any method for both matrix and dataframe class? If we save this table and read it the class will be dataframe as default. Thanks a lot.