我正在抓取一些數據誰的數據是/h2/a
,但a的href應該包含http://www.thedomain.com
。所有鏈接都是這樣的: thedomain.com/test
等等。現在我只獲取文本,而不是href鏈接本身的名稱。獲取鏈接名稱href <a>標籤nokogiri
例如:
<h2>
<a href="http://www.thedomain.com/test">Hey there</a>
<a href="http://www.thedomain.com/test1">2nd link</a>
<a href="http://www.thedomain.com/test2">3rd link</a>
</h2>
這裏是我的代碼:
html_doc.xpath('//h2/a[contains(@href, "http://www.thedomain.com")]/text()')
嘿,第二個環節,第3連桿
而我想http://www.thedomain.com/test
等。