How to match certain text in returned XPath HTML?
I am using Xpath in Ruby with following statement.
print XPath.first(Document.new(html),"//tr[@id='ctl00_c1_rr_ci_trAdd']//td[2]")
The Query return the following text.
<td>
1371 N Belsay开发者_如何学C Rd<br/>Burton, MI 48509
<br/>
<a href='http://www.mapquest.com/maps/map.adp?style=2&address=1371+N+Belsay+Rd&city=Burton&state=MI&zip=48509' class='rptLnk2' id='ctl00_c1_rr_ci_hlMapQuest' target='_blank'>See the location on a Mapquest Map</a>
<br/>
<a href='http://maps.google.com?q=1371+N+Belsay+Rd Burton, MI 48509' class='rptLnk2' id='ctl00_c1_rr_ci_hlGoogleMaps' target='_blank'>See the location on a Google Map</a>
</td>
But I just want this text
1371 N Belsay Rd<br/>Burton, MI 48509
Can anyone tell me how to achieve this? When I am using scan statement - I am getting this error.
private method `scan' called for <td> ... </>:REXML::Element (NoMethodError)
An XPath expression to get this text 1371 N Belsay Rd
-- as a text node, is:
((//tr[@id='ctl00_c1_rr_ci_trAdd'])//td)[2]/text()[1]
In case you want the expression to select the three nodes:
1371 N Belsay Rd<br/>Burton, MI 48509
you may use this one:
normalize-space(((//tr[@id='ctl00_c1_rr_ci_trAdd'])//td)
[2]
/node()[not(position() > 3)])
精彩评论