R xpathsaply()返回行(),请返回h3lp
嗨,我无法让这个函数工作 在网页上: 有与memName类的链接,例如:R xpathsaply()返回行(),请返回h3lp,r,R,嗨,我无法让这个函数工作 在网页上: 有与memName类的链接,例如: <a href="http://www.meetup.com/stats-prog-dc/members/94995702/" class="memName">Asuri</a> 在R中,我键入以下命令: >web <- getURL("http://www.meetup.com/stats-prog-dc/members/?sort=chapter_member.atime&a
<a href="http://www.meetup.com/stats-prog-dc/members/94995702/" class="memName">Asuri</a>
在R中,我键入以下命令:
>web <- getURL("http://www.meetup.com/stats-prog-dc/members/?sort=chapter_member.atime&desc=1&offset=3", ssl.verifypeer = FALSE)
>webhtml <- htmlTreeParse(web,error=function( ...){},useInternalNodes=TRUE,encoding="UTF-8",trim=TRUE)
>vNames <- xpathSApply(webhtml,'//*[@class="memName "]', xmlValue)
>vNames
>web webhtml vNames vNames
问题是vNames返回“list()”而不是包含“Asuri”和所有其他名称的列表。请问为什么它不工作,这是杀死我,在R的帮助是如此不清楚
如果我没有在htmlTreeParse(web)中放置参数,为什么xpathSApply会返回错误?
XPathApply中的参数xmlValue是什么?它的帮助页面甚至没有提到 您已经在属性名称中添加了一个空格。使用
xpathSApply(webhtml,'//*[@class="memName"]', xmlValue)
[1] "James Conkling" "Mary Clare Peate" "Mike Hodel"
[4] "Harlan Harris" "kenny" "Alex McKenzie"
[7] "KJ" "shaema talib" "Brian Sacash"
[10] "fbohorqu" "Peter" "Steve Swartz"
[13] "Russell" "J. Kader Hyer" "T Woo"
[16] "Rajavel Sethupathi" "Clarence Dillon" "Patrick Wheatley"
[19] "Anna Shaver" "anupam"
相反
xmlValue
提供特定节点的值<代码>?xmlValue将为您提供帮助页面xpathsaply
有一个参数fun
,用于将函数应用于每个节点。
如果需要特定节点的属性,可以使用例如xmlAttrs
:
> xpathSApply(webhtml,'//*[@class="memName"]',xmlAttrs)
[,1]
href "http://www.meetup.com/stats-prog-dc/members/37625662/"
class "memName"
[,2]
href "http://www.meetup.com/stats-prog-dc/members/94691152/"
class "memName"
[,3]
href "http://www.meetup.com/stats-prog-dc/members/91583452/"
class "memName"
很好,谢谢,现在我了解更多了,对不起,我是R和脚本新手