[英]AJAX click on button using Perl WWW:Mechanize
我正在為一個客戶執行一個項目,他需要能夠掃描特定頁面上的目錄。 我已經修改了他的現有代碼以運行循環,因為現在有多個頁面可以從中提取內容。 我要從中掃過的頁面之一: https : //marriage.ag.gov.au/marriagecelebrants/civil
您可以看到有162個頁面看起來正在AJAX上運行以加載下一個內容。 現有代碼將基於輸入名稱屬性單擊:
ctl00 $ MainContent $ gridCelebrants $ ctl00 $ ctl02 $ ctl00 $ ctl04到目前為止,我的所有代碼實際上基本上是刷新頁面並掃描相同的內容162次。
這是當前片段:
use warnings;
use WWW::Mechanize;
use Data::Dumper;
use HTML::TableExtract;
use Spreadsheet::WriteExcel;
#header();
# create max page array to handle civil and other page.
# number indicates how many times to click through
# first item in array is https://marriage.ag.gov.au/marriagecelebrants/civil
# second item is https://marriage.ag.gov.au/marriagecelebrants/other
my @max_page_array = qw(
162
11
);
# create URL array for the 2 pages to scrape
my @url_array = qw(
https://marriage.ag.gov.au/marriagecelebrants/civil
https://marriage.ag.gov.au/marriagecelebrants/other
);
# get size of array
my $url_array_size = scalar @url_array;
# declare vars
my $n = 0;
my $i = 0;
# time to loop through the url's
while( $i < $url_array_size){
open (raw, ">output-dev-$i.txt");
close(raw);
$n = 0;
my $mech = WWW::Mechanize->new(autocheck => 1);
$mech->get( $url_array[$i] );
open (raw, ">>output-dev-$i.txt");
while($n < $max_page_array[$i]){
my $c = $mech->content;
my $te = HTML::TableExtract->new(br_translate => 1,keep_html => 0);
$te->parse($c);
foreach my $ts ($te->tables) {
foreach my $row ($ts->rows) {
print raw join(',', @$row);
}
}
#this was existing code
#$mech->click( "ctl00\$MainContent\$gridCelebrants\$ctl00\$ctl02\$ctl00\$ctl04" );
#tried multiple variations based on documentation and got nowhere
$mech->click_button( 'ctl00$MainContent$gridCelebrants$ctl00$ctl02$ctl00$ctl04' );
$n++;
}
close raw;
$i++;
} # while loop - url array size
我的問題是,當您單擊下一步時,如何獲取我的perl腳本來加載下一頁並清除下一組數據?
我的問題是,當您單擊下一步時,如何獲取我的perl腳本來加載下一頁並清除下一組數據?
根據FAQ , WWW :: Mechanize不支持JavaScript。 它提供了替代方法的列表,另請參見WWW :: Mechanize :: PhantomJS 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.