使用WWW :: Mechanize :: Firefox来使用onclick

时间:2013-10-07 21:22:09

标签: perl web-scraping www-mechanize-firefox

我需要能够关注网页上的onclick。这是我到目前为止的代码。

use strict;
use warnings;
use WWW::Mechanize::Firefox;

# Create a new instance of Mechanize
my $mech = WWW::Mechanize::Firefox->new();

# Go to page
$mech->get('http://www.website.com');

# TODO
# use a buttons onclick somehow....

1 个答案:

答案 0 :(得分:1)

# Go to page
$mech->get('http://www.google.com');

# Fill in the query box
$mech->field( q => "turtles" );

# Click the Feeling Lucky Button
$mech->click( { xpath => '//button[@name="btnI"]' } );

# Get the title of the result page
my $page_title = $mech->title();

print "$page_title\n";

documentation非常有助于提出这个问题。