Forum: Ruby clicking links in mechanize with :text=> nokogiri.css('a.l')

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.
25ae00f7825b9b6ddc7db1fb7b589f34?d=identicon&s=25 Edouard Dantes (edouard)
on 2009-01-29 11:14
Hi,

i cannot click links in mechanize through their text content.

i tried the following but get error with link_with(:text => '') method
or using the whole text content obtained through nokogiri parser method
css('a.l') that points to google results.

what am i doing wrong?

thanks for input


#!/usr/bin/env ruby

require 'rubygems'
require 'mechanize'
$KCODE='UTF8'

@agent= WWW::Mechanize.new
@page=@agent.get('http://www.google.com/search?q=parsing')

puts @agent.click @page.link_with(:text => 'parsing') <===??

@page.parser.css('a.l').each do |l| puts @agent.click(l).inner_text end
<===??
7e593ac63e5f25649b701dc25f69d1b7?d=identicon&s=25 Luis Parravicini (Guest)
on 2009-01-29 16:55
(Received via mailing list)
On Thu, Jan 29, 2009 at 8:11 AM, Edouard Dantes <edrd.dantes@gmail.com>
wrote:
> i cannot click links in mechanize through their text content.
>
> i tried the following but get error with link_with(:text => '') method
> or using the whole text content obtained through nokogiri parser method
> css('a.l') that points to google results.

> ...
> @agent= WWW::Mechanize.new
> @page=@agent.get('http://www.google.com/search?q=parsing')
>
> puts @agent.click @page.link_with(:text => 'parsing') <===??

  There is no link with text 'parsing'. Just tried that google search
and there's a 'Parsing' result on the first page.
@page.link_with(:text => 'Parsing') returns a WWW::Mechanize::Page::Link
0c2903022784f514db2a12d09e3ae491?d=identicon&s=25 Ins Mou (insmou)
on 2014-05-15 13:42
i'm new in ruby and i want to understand how to use nokogiri mechanize
to parse pages in HTML
This topic is locked and can not be replied to.