编辑:最终使用WWW::Mechanize::Firefox。下面我回答了我自己的问题。
我正在尝试访问一个网站并下载它的网页。cloudflare DDOS在网站上的保护偶尔会出现,我不能让LWP通过它。我可以成功地检测到一个页面是使用regex /Ray ID: [a-f0-9]*/的cloudflare启动页,但是每当我再次尝试连接时,我只会得到一个新的射线ID的启动屏幕。
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$ua->agent('Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0 Iceweasel/31.3.0');
$signin_url = 'my url';
$signin_page = $ua->get($signin_url);
if($signin_page->content =~ /Ray ID: ([a-f0-9]*)/i) {
print "DDOS protection page here\n";
#more code to retry, but just gets back into this part of the IF
} else {
print "Not the DDOS page\n";
#now I would save to file
}因为那不管用,所以我得换个办法。
发布于 2015-03-21 03:36:55
Cloudflare需要Javascript,所以我使用了WWW::Mechanize::Firefox。像这样
#!/usr/bin/perl
use WWW::Mechanize::Firefox;
system('firefox &'); #The & makes it so the program doesn't wait.
sleep 5; #So firefox can load
$mech = WWW::Mechanize::Firefox->new;
$mech->get('http://www.mycloudflareblockedwebsite.com/');
if($mech->content =~ /Test if it is the CLOUDFLARE source HTML page/) {
sleep 10; #Wait for cloudflare to do it's thing
}达达!
我花了很长时间才这么做。
发布于 2015-03-15 10:34:34
DDOS保护拦截请求,设置cookie,然后将您重定向到目标页面。您必须在下一个请求中提交从拦截中获得的cookie,以通过DDOS保护。如果您创建一个cookie jar,LWP将为您做这件事。
LWP::UserAgent->new( cookie_jar => {} )WWW:机械化是LWP::UserAgent的子类,它将该参数传递给LWP::UserAgent,以便您也可以使用
use WWW::Mechanize;
my $ua = WWW::Mechanize->new;当LWP::UserAgent或WWW::Mechanize UA有cookie jar时,get将自动接受cookie,遵循重定向,并在随后的请求中提交cookie。
https://stackoverflow.com/questions/29057331
复制相似问题