1

我想从此链接获取所有“样本”ID ,我的意思是所有 ID,例如“GSM545657”、“GSM545658”...。我想用新的包rvest来解决我的问题,但是我对 CSS 和 xpath 不熟悉。我使用 selectorgadget来获取 CSS 选择器。我选择了第一个 ID:“GSM545657”,它变成了绿色,然后我删除了我不想要的信息(它们变成了红色)。现在,所有样品 ID 都是绿色或红色。CSS 选择器显示如下:"tr:nth-child(23) .eye-protector-processed a" 。我的代码是这样显示的

Library(rvest);
myhtml<-html("http://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE21610");
myhtml %>% html_nodes("tr:nth-child(23) .eye-protector-processed a") %>%html_text()

并且我将错误错误类(输出)<-“XMLNodeSet”:尝试将属性设置为NULL 如果我只选择两个ID,例如“GSM545665”和“GSM545666”,我可以使用

myhtml %>% html_nodes("tr:nth-child(23) .eye-protector-processed a") %>%html_text()

并得到结果,你能告诉我如何解决这个问题,我们将不胜感激。非常感谢!

4

1 回答 1

0

我认为您使用了错误的选择器。这对我有用:

myhtml <- html("http://www.ncbi.nlm.nih.gov/geo/query/acc.cgi?acc=GSE21610")
myhtml %>% 
  html_nodes("tr:nth-child(23) tr a") %>%
  html_text()

(但 rvest 应该会给出更好的错误。我会提交一个错误)

于 2014-12-06T13:42:17.433 回答