【发布时间】:2015-04-17 18:27:18
【问题描述】:
鉴于下面的示例,谁能告诉我如何使用 Nokogiri 和 Mechanize 将每个 <h4> 标签下的所有链接放在不同的组中,即以下所有链接:
- “一些文字”
- “还有一些文字”
- “一些额外的文字”
<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>
【问题讨论】:
标签: ruby web-scraping nokogiri mechanize