给出下面的示例,任何人都可以告诉我如何使用Nokogiri和机械化来获得每个<h4>
标签下的所有链接,分别在I.E.如何使用机械化和nokogiri红宝石
- “一些文本”
- “一些文字”
- “一些额外的文本”
<div id="right_holder">
<h3><a href="#"><img src="http://example.com" width="11" height="11"></a></h3>
<br />
<br />
<h4><a href="#">Some text</a></h4>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<br />
<br />
<h4><a href="#">Some more text</a></h4>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<br />
<br />
<h4><a href="#">Some additional text</a></h4>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
<a href="#" alt="name of item"><img src="http://some.image.com" class="class1"></a>
</div>
这得到所有链接,但不根据
标签分开它们,我需要知道每个链接的哪个
标签来自。谢谢 – akhanaton
我更新了我的解决方案,以遵循我已链接的策略。我的原始解决方案有'h4 a'链接作为数组中的第一个链接,但它也包含了'h4'之前的任何链接。 – Ebtoulson
谢谢,似乎工作。 – akhanaton