3

I have a html that looks like:

<div class="date_s">May 16, 2018</div>
<div class="date_a">May 17, 2018</div>
<div class="date_g23">May 18, 2018</div>

I can extract a specific div class with:

XML::xpathSApply(XML::htmlParse(myurl), "//div[@class='date_s']", XML::saveXML)

How can I extract all div class that start with 'date' ?

I have tried in vain (returns an empty list):

XML::xpathSApply(XML::htmlParse(myurl), "//div[starts-with(name(), 'date')]", XML::saveXML)
RockScience
  • 17,932
  • 26
  • 89
  • 125

2 Answers2

2

Your code is basically correct, just use @class instead of name():

XML::xpathSApply(XML::htmlParse(myurl), 
                 "//div[starts-with(@class, 'date')]", XML::saveXML)

[1] "<div class=\"date_s\">May 16, 2018</div>"  
[2] "<div class=\"date_a\">May 17, 2018</div>"  
[3] "<div class=\"date_g23\">May 18, 2018</div>"
andrew_reece
  • 20,390
  • 3
  • 33
  • 58
0

You can get whole list by

document.querySelectorAll("div[class^='date']" );
Prany
  • 2,078
  • 2
  • 13
  • 31