我想用R来刮这个页面:(http://www.fifa.com/worldcup/archive/germany2006/results/matches/match=97410001/report.html )和其他人,以获得目标得分手和时间。
到目前为止,这就是我所拥有的:
require(RCurl)
require(XML)
theURL <-"http://www.fifa.com/worldcup/archive/germany2006/results/matches/match=97410001/report.html"
webpage <- getURL(theURL, header=FALSE, verbose=TRUE)
webpagecont <- readLines(tc <- textConnection(webpage)); close(tc)
pagetree <- htmlTreeParse(webpagecont, error=function(...){}, useInternalNodes = TRUE)
pagetree对象现在包含指向我解析的html的指针(我认为)。我想要的部分是:
<div class="cont")<ul>
<div class="bold medium">Goals scored</div>
<li>Philipp LAHM (GER) 6', </li>
<li>Paulo WANCHOPE (CRC) 12', </li>
<li>Miroslav KLOSE (GER) 17', </li>
<li>Miroslav KLOSE (GER) 61', </li>
<li>Paulo WANCHOPE (CRC) 73', </li>
<li>Torsten FRINGS (GER) 87'</li>
</ul></div>
但坦白说,我现在已经迷失了如何孤立它们 xpathSApply
和 xpathApply
混淆了我的蜜蜂!
那么,有没有人知道如何制定一个命令来吸出其中包含的元素 <div class="cont">
标签?