regex - why I can not fetch source code from the website in perl? -


i want fetch source code of website : https://www.splithistory.com/zsl/ gives error, tried www::mechanize , lwp::simple got error :error geting website not found @ j:\perl_project\demo_spli.pl line 9. when try fetch data website : https://www.splithistory.com/aapl/ works ok.....

here code

#!/usr/bin/perl #!perl -w use dbi; use strict; use www::mechanize;  $mech= www::mechanize->new(); $url= 'https://www.splithistory.com/zsl/'; $mech -> get($url); $script = $mech -> content; open (myfile, '>sd.txt');   #open file in write mode print myfile $script;       #copy source code of website in file close(myfile); 

output:

error geting https://www.splithistory.com/zsl/: not found @ j:\perl_project\demo_spli.pl line 9. 

error geting https://www.splithistory.com/zsl/: not found @ j:\perl_project\demo_spli.pl line 9.

that's because site returns "404 not found" inside http header. successful response have status code 200:

http/1.1 404 not found date: mon, 08 aug 2016 18:50:46 gmt server: apache/2.2.31 (unix) mod_ssl/2.2.31 openssl/1.0.2h mod_jk/1.2.40 mod_perl/2.0.9 perl/v5.8.9 transfer-encoding: chunked content-type: text/html; charset=iso-8859-1

www::mechanize croak if web site returns error , that's see. data anyway use:

eval { $mech->get($url); }; $res = $mech->res(); $script = $res->content; 

Comments