You can just take the href
attribute from the link:
m = Mechanize.new
page = m.get("yourpage")
page.link_with(:text => "bla bla").href #=> "http://www.edu/st/file.html"
Pregunta
I have similar HTML in one of my pages (with form name):
<form name="test">
<td> <A HREF="http://www.edu/st/file.html">bla bla</A> </td>
<td> <A HREF="http://www.mac/spgm/file.html">boo bla</A> </td>
<td> <A HREF="http://www.dom/st/file.html">foo</A> </td>
</form>
Another page without form name:
<td> <A HREF="http://www.edu/st/file.html">bla bla</A> </td>
<td> <A HREF="http://www.mac/spgm/file.html">boo bla</A> </td>
<td> <A HREF="http://www.dom/st/file.html">foo</A> </td>
In both cases I have the values bla bla
, boo
, foo
. Using the values, can I get the respective href
values using Mechanize?
Solución
You can just take the href
attribute from the link:
m = Mechanize.new
page = m.get("yourpage")
page.link_with(:text => "bla bla").href #=> "http://www.edu/st/file.html"
Otros consejos
You could try iterating over all of the links on the page and checking if the text is the same.
doc.xpath('//a[@href]').each do |link|
if link.text.strip == "bla bla"
# Your code here.
end