【发布时间】:2014-09-01 10:36:39
【问题描述】:
您好,我正在使用 R 中的 XML 包来抓取 html 页面。感兴趣的页面是http://www.ncbi.nlm.nih.gov/protein/225903367?report=fasta,并且在该页面上有一个序列,当检查 chrome 中的元素时,xpath 是
//*[@id="gi_225903367_141"]
但是当我尝试使用:
xpathSApply(htmlParse(fasta.url.content),"//*[@id="viewercontent1"]/pre")
Error: unexpected symbol in "xpathSApply(htmlParse(fasta.url.content),"//*[@id="viewercontent1"
我收到上述错误。
XML 包是否对 xpath 很挑剔?
这是使用 Mathius 提供的 xpath 的查询
xpathSApply(htmlParse(fasta.url.content),"//span[contains(@id,'gi_225903367_1')]")
list()
attr(,"class")
[1] "XMLNodeSet"
我得到一个空列表。我不怀疑 xpath 不正确,但我想知道这是否与 R 相关。
【问题讨论】:
-
尝试将内部双引号更改为单引号。作为
//*[@id='viewercontent1']/pre -
这似乎有效,但是收到一个空列表...
-
我不确定我是否理解您所追求的元素。是
//*[@id="gi_225903367_141"]还是//*[@id="viewercontent1"]/pre还是//*[@id="viewercontent1]"? -
是MYS开头的序列
-
那么,
MYS是什么?请简单回答我的问题,您在寻找什么 HTML 元素?
标签: xml r xpath web-scraping