Website Access - WWW :: Mechanization

I am trying to use the code as shown below to get the htm source website and it works. However, I cannot get the result when I visit the website http://reserve.apple.com/WebObjects/ProductReservation.woa/wa/reserveProduct using the code as shown below. But I can access this page using a browser. Could you give me some hints or tips to fix this problem? Thanks.

#!/usr/bin/perl use strict; use warnings; # create a new browser use WWW::Mechanize; my $browser = WWW::Mechanize->new(); # tell it to get the main page my $sURL = 'http://www.apple.com'; #my $sURL = 'http://reserve.apple.com/WebObjects/ProductReservation.woa/wa/reserveProduct'; $browser->get($sURL); print $browser->content; exit(0); 
+6
source share
1 answer

This is a strange behavior, but a site with the URL you want to get requires the following headers: Accept, Encoding, Accept-Language, Accept-Charset, Cookie.

Otherwise, the server does not respond at all.

You can easily do this by simply pasting the following code before the get request:

 $browser->add_header( "Accept" => "", "Accept-Encoding" => "", "Accept-Language" => "", "Accept-Charset" => "", "Cookie" => "" ); 

Instead of empty fields, you can insert some real values, but this also works.

+6
source

Source: https://habr.com/ru/post/901374/


All Articles