小编Jes*_*man的帖子

Nokogiri 和 Xpath:查找两个标签之间的所有文本

我不确定这是语法还是版本差异的问题,但我似乎无法弄清楚这一点。我想将(非关闭)内的数据tdh2标签带到h3标签。这是 HTML 的样子。

<td valign="top" width="350">
    <br><h2>NameIWant</h2><br>
    <br>Town<br>

    PhoneNumber<br>
    <a href="mailto:emailIwant@nowhere.com" class="links">emailIwant@nowhere.com</a>
    <br>
    <a href="http://websiteIwant.com" class="links">websiteIwant.com</a>
    <br><br>    
    <br><img src="images/spacer.gif"/><br>

    <h3><b>I want to stop before this!</b></h3>
    Lorem Ipsum Yadda Yadda<br>
    <img src="images/spacer.gif" border="0" width="20" height="11" alt=""/><br>
    <td width="25">
        <img src="images/spacer.gif" border="0" width="20" height="8" alt=""/>
        <td valign="top" width="200"><img src="images/spacer.gif"/>
            <br>
            <br>

            <table cellspacing="0" cellpadding="0" border="0"/>205"&gt;<tr><td>
                <a href="http://dontneedthis.com">
                </a></td></tr><br>
            <table border="0" cellpadding="3" cellspacing="0" width="200">
            ...
Run Code Online (Sandbox Code Playgroud)

<td valign>不关闭,直到最底层,我认为可能是为什么我有问题的网页。

我的 Ruby 代码如下所示:

require 'open-uri'
require 'nokogiri'

@doc …
Run Code Online (Sandbox Code Playgroud)

html ruby xpath nokogiri

4
推荐指数
1
解决办法
2141
查看次数

标签 统计

html ×1

nokogiri ×1

ruby ×1

xpath ×1