0

我正在使用rvest包从网站http://www.wp.pl/下载信息,但我只对带有特殊标签的链接感兴趣,data-cluster比如这个

<a data-cluster="3" href="http://wp.tv/i,nowe-prawo-drogowe-juz-latem-nowelizacja-czeka-na-podpis,mid,1659098,klip.html" title="Bat na kierowców już latem? &quot;To będzie trzęsienie ziemi&quot;" data-st-mtype="3">
<img src="http://y.wpimg.pl/i/ivar/G/201503/1426152344_a.jpg" data-src="http://y.wpimg.pl/i/ivar/G/201503/1426152344_a.jpg" alt="" height="191" width="332">
<h3>Bat na kierowców już latem? "To będzie trzęsienie ziemi"</h3>
</a>

关于如何在html_nodes()函数中指定选择器的任何想法?

4

1 回答 1

1

为什么不直接使用xpath:

library(rvest)
html('<a blah="1">123</a><a href="">345</a><a href="">789</a><a blah="2" href="">345</a>') %>%
  html_nodes(xpath = '//a[@blah]')
# [[1]]
# <a blah="1">123</a> 
#   
# [[2]]
# <a blah="2" href="">345</a> 
#   
#   attr(,"class")
# [1] "XMLNodeSet
于 2015-03-13T10:04:42.730 回答