我有以下 html 并且想知道如何使用 xpath 来检索所有信息: - 姓名(名字,姓氏) - 昵称 - 电子邮件 - 送货地址......
首先,在<BR>
. 提前谢谢了。
<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>
在发布上述问题后,我了解到我可以做到这些,但看起来并不干净:
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}"
我现在的问题是为什么 html.xpath("//span/text()[contains(., 'Buyer')]") 返回 TEXT 本身而不是 ELEMENT。再次,谢谢!!