我试图在页面上获取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]
有什么想法吗? THX
答案 0 :(得分: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