【发布时间】:2014-09-11 13:19:27
【问题描述】:
非常感谢有关如何提取这家公司设有办事处的四个城市名称的指导。 Firebug 在 cufontext 下的名称是灰色的,例如 <cufontext>MEMPHIS</cufontext>,而 MEMPHIS 是灰色的。顺便说一句,我不介意返回一些无关的文本,例如状态或地址。展示了我的三个失败的努力。
library(XML)
doc <- htmlTreeParse('http://www.lewisthomason.com/locations/', useInternal = TRUE, asText = TRUE)
xpathSApply(doc, "//div[@id = 'the_content']", xmlValue, trim = TRUE) # returns list()
xpathSApply(doc, "//div[@id = 'the_content']/div/h3//cufon", xmlValue, trim = TRUE) # returns NULL
xpathSApply(doc, "//div[@id = 'the_content']//cufon[@class = 'cufon cufon-canvas']", xmlValue, trim = TRUE) # returns NULL
非常感谢。
【问题讨论】:
-
另外,
rl <- readLines(url); htmlTreeParse(rl, asText = TRUE)似乎有效。 -
@RichardScriven:谢谢。从站点获取 HTML 不是问题。提取城市的 XPath 表达式阻碍了我和下面的建议答案。