使用 Mechanize 获取不带 CLASS 或 ID 的 HREF 值
Get HREF values without CLASS or ID using Mechanize
我正在尝试获取页面上的 HREF 值,但没有 CLASS 或 ID。
<div class="columns">
<a href="http://www.website.com/page.html?id=123"></a>
</div>
我试过了,
a = Mechanize.new
page = a.get("http://www.website.com/index.html")
url = page.links_with(:href => "^http://www.website.com/page.html?id=").href
puts url[0]
有什么想法吗?谢谢
尝试关注。
a = Mechanize.new
page = a.get("http://www.website.com/index.html")
url = page.link_with(:text => "http://www.website.com/page.html?id=")
puts url
更新答案:
a = Mechanize.new
page = a.get("http://www.sainte-maxime.com/-locations-de-vacances-.html")
urls = page.links_with(:href => /.*?id\=/).map{|h| h.href}
puts urls
我正在尝试获取页面上的 HREF 值,但没有 CLASS 或 ID。
<div class="columns">
<a href="http://www.website.com/page.html?id=123"></a>
</div>
我试过了,
a = Mechanize.new
page = a.get("http://www.website.com/index.html")
url = page.links_with(:href => "^http://www.website.com/page.html?id=").href
puts url[0]
有什么想法吗?谢谢
尝试关注。
a = Mechanize.new
page = a.get("http://www.website.com/index.html")
url = page.link_with(:text => "http://www.website.com/page.html?id=")
puts url
更新答案:
a = Mechanize.new
page = a.get("http://www.sainte-maxime.com/-locations-de-vacances-.html")
urls = page.links_with(:href => /.*?id\=/).map{|h| h.href}
puts urls