Forum: Ruby Clicking link with WWW::Mechanize

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Peter S. (Guest)
on 2007-03-28 14:44
(Received via mailing list)
Hello,

I wuold like to click on a link in WWW::Mechaznie, and I know only the
Hpricot XPath of the element I would like to click, nothing more. While
it's certainly possible to look up the text of the element pointed to by
the XPath, there can be more elements with that text, but only one
element with that XPath.

Is this possible with Mechanize somehow?


Thanks,
Peter

__
http://www.rubyrailways.com :: Ruby and Web2.0 blog
http://scrubyt.org :: Ruby web scraping framework
http://rubykitchensink.ca/ :: The indexed archive of all things Ruby.
Aaron P. (Guest)
on 2007-03-28 19:52
(Received via mailing list)
Hi Peter,

On Wed, Mar 28, 2007 at 07:44:08PM +0900, Peter S. wrote:
> Hello,
>
> I wuold like to click on a link in WWW::Mechaznie, and I know only the
> Hpricot XPath of the element I would like to click, nothing more. While
> it's certainly possible to look up the text of the element pointed to by
> the XPath, there can be more elements with that text, but only one
> element with that XPath.
>
> Is this possible with Mechanize somehow?

Yes, this is possible.  Mechanize can click an hpricot element, as long
as it has an 'href', or a 'src' attribute.  For example:

  page = mech.get('http://example.com/')
  new_page = mech.click((page/'//some/xpath/a'))

If you've got more questions, don't forget about the mechanize mailing
list:

  http://rubyforge.org/mailman/listinfo/mechanize-users

Hope that helps!
Peter S. (Guest)
on 2007-03-28 23:58
(Received via mailing list)
Aaron P. wrote:
>>
>> Is this possible with Mechanize somehow?
>
> Yes, this is possible.  Mechanize can click an hpricot element, as long
> as it has an 'href', or a 'src' attribute.  For example:
>
>   page = mech.get('http://example.com/')
>   new_page = mech.click((page/'//some/xpath/a'))

Hey, thanks Aaron! I am really glad that this is possible!

> If you've got more questions, don't forget about the mechanize mailing
> list:
>
>   http://rubyforge.org/mailman/listinfo/mechanize-users

Sure, I am going to subscribe right now!

Cheers,
Peter
_
http://www.rubyrailways.com :: Ruby and Web2.0 blog
http://scrubyt.org :: Ruby web scraping framework
http://rubykitchensink.ca/ :: The indexed archive of all things Ruby.
This topic is locked and can not be replied to.