开发者

Mechanize::Firefox gets stuck

开发者 https://www.devze.com 2023-01-20 09:58 出处:网络
I\'m using WWW::Mechanize::Firefox to crawl pages that load some JavaScript after they have been loaded.

I'm using WWW::Mechanize::Firefox to crawl pages that load some JavaScript after they have been loaded.

My code regarding this problem:

my ($firemech) = WWW::Mechanize::Firefox->new(tab => 'current', );
$firemech->get($url);
die "Cannot connect to $u开发者_如何学JAVArl\n" if !$firemech->success();

print "I'm connected!\n";

my ($retries) = 10;
while ($retries-- and ! $firemech->is_visible( xpath => '//*[@class="areaMapC"]' )) {
    sleep 1;
}
die "Timeout" unless $retries;

my ($content) = $firemech->content();

Everything goes fine for the first page, it loads the page and recognizes the class that loads later. Then, it changes to the second page correctly (I see Firefox changing it), but it never gets to the "I'm connected!" print.

I checked the URL and that the wanted class is there, the code it's the same for both the pages (except some IDs which I want to extract). I really have no clue what's going wrong.

A page of this kind is HERE.


I solved this one by simply using

my ($firemech) = WWW::Mechanize::Firefox->new();

Instead of what I used before. It still keeps the content in one tab so it works perfectly with my needs.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号