I have the following html and like to know how to use xpath to retrieve all the info: - Name(first, last) - Nick Name - email - shipping address...
Primarily, retrieve text after <BR>
. Many Thanks in advance.
<table>
<tr>
<td valign="top" width="50%" align="left">
<span>Buyer</span><br/>FirstName LastName<br/>NickName<br/>First.Last@SomeCompany.com</td>
<tr><td valign="top" width="40%" align="left">
<span><span>Shipping address - </span><span>confirmed</span></span><br/>FirstName LastName<br/>Attn: FirstName<br/>1234 Main St.<br/>TheCity, TheState, 12345<br/>United States<br/></td>
</tr></table>
After I posted the above question, I learned that I can do these, but does not look clean:
buyer = html.xpath("//span/text()[contains(., 'Buyer')]").first.parent
buyer_name = buyer.next.next
puts "Buyer's Full name: #{buyer_name.text}"
buyer_nick = buyer_name.next.next
puts "Buyer's Nick name: #{buyer_nick.text}"
buyer_email = buyer_nick.next.next
puts "Buyer's email: #{buyer_email.text}"
My question now is why the html.xpath("//span/text()[contains(., 'Buyer')]") return the TEXT itself instead of the ELEMENT. Again, thanks!!
` for immediate processing it's fine because it's not changing the structure. Like I said in the answer, `
` is a problem-child. I wouldn't do it with other tags, except maybe `
` on rare occasion.
– the Tin Man Apr 05 '12 at 03:28