lwp

How can I make LWP::UserAgent look like another browser?

心不动则不痛 提交于 2019-12-09 16:19:48
问题 This is my first post on SO, so be gentle. I'm not even sure if this belongs here, but here goes. I want to access some information on one of my personal accounts. The website is poorly written and requires me to manually input the date I want the information for. It is truly a pain. I have been looking for an excuse to learn more Perl so I thought this would be a great opportunity. My plan was to write a Perl script that would login to my account and query the information for me. However, I

Why can't I fetch wikipedia pages with LWP::Simple?

南笙酒味 提交于 2019-12-09 02:44:39
问题 I'm trying to fetch Wikipedia pages using LWP::Simple, but they're not coming back. This code: #!/usr/bin/perl use strict; use LWP::Simple; print get("http://en.wikipedia.org/wiki/Stack_overflow"); doesn't print anything. But if I use some other webpage, say http://www.google.com , it works fine. Is there some other name that I should be using to refer to Wikipedia pages? What could be going on here? 回答1: Apparently Wikipedia blocks LWP::Simple requests: http://www.perlmonks.org/?node_id

Why does my image download with Perl's LWP give me the wrong-sized file?

大憨熊 提交于 2019-12-08 19:26:46
问题 I am trying to get an image from an HTTP server using Perl. I have the full URL of the file and am attempting to use my $data = LWP::Simple::get $params{URL}; my $filename = "image.jpg"; open (FH, ">$filename"); print FH $data; close (FH); Now, logically, to me at least, this should work. But the files are slightly different sizes, and I can't work out why. Help! 回答1: You need to use binmode to properly write the image data to disk. my $data = LWP::Simple::get $params{URL}; my $filename =

Perl LWP::Simple HTTPS error

牧云@^-^@ 提交于 2019-12-08 00:53:19
问题 I am trying to get the contents of a website and print. The code worked how I wanted it to work with a regular HTTP website, but it will not work with HTTPS. I have looked up fixes for this issue, but they are not working in my program. This is the code I currently have: #! usr/bin/perl use strict; use warnings; use LWP::Simple; use LWP::UserAgent; use 5.014; $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; my $ua = LWP::UserAgent->new(); $ua->ssl_opts( verify_hostnames => 0 ); getprint('https://

How do I create a gzip compressed HTTP::Response?

倾然丶 夕夏残阳落幕 提交于 2019-12-07 18:18:38
问题 I need to create an HTTP::Response with compressed data. How do I go about making the content gzipped? Do I just add the appropriate headers and compress it myself using Compress::Zlib? Or does any of the LWP modules provide a method for handling this? 回答1: Is this what you need? You gzip the data, set the Content-encoding header, and send it off. use strict; use warnings; use HTTP::Response; use IO::Compress::Gzip qw(gzip); my $data = q(My cat's name is Buster); my $gzipped_data; my $gzip =

Why does Perl's LWP gives me a different encoding than the original website?

风格不统一 提交于 2019-12-07 16:08:38
问题 Lets say i have this code: use strict; use LWP qw ( get ); my $content = get ( "http://www.msn.co.il" ); print STDERR $content; The error log shows something like "\xd7\x9c\xd7\x94\xd7\x93\xd7\xa4\xd7\xa1\xd7\x94" which i'm guessing it's utf-16 ? The website's encoding is with <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1255"> so why these characters appear and not the windows-1255 chars ? And, another weird thing is that i have two servers: the first server returning

I cannot Connect to any HTTPS site using LWP::UserAgent

笑着哭i 提交于 2019-12-07 02:32:22
问题 I am trying to create a script that simply just connect to a website. However, for some reason it will not connect to anything that is using HTTPS. We have a proxy enabled here. However, I believe the proxy is not the problem, because if I were to connect to an HTTPS inside the network that does not tunnel through a proxy it still fails. If I were to run this program on any site that is not using HTTPS, I can get through and the script works as intended. What I'm wondering is what could

handle lwp timeout effectively

半城伤御伤魂 提交于 2019-12-07 01:43:56
问题 I am using LWP to download content from web pages, and I would like to limit the amount of time it waits for a page. This is accomplished in lwp like this: my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->get($url); And this works fine, except for whenever the timeout reaches its limit, it just dies and I can't continue on with the script! I'd really like to handle this timeout properly so that I can record that the url had a timeout and then move on to my next one. Does anyone know how

alarm Escaping Perl 'eval' block

↘锁芯ラ 提交于 2019-12-06 13:37:32
问题 I have a Perl script that automatically downloads content from various sources. It does the downloading in an eval block with an alarm so that the attempt will time out if it takes too long: eval { alarm(5); my $res = $ua->request($req); $status = $res->is_success; $rawContent = $res->content; $httpCode = $res->code; alarm(0); }; This has worked for years, but after doing some system updates, all of a sudden it quit working. Instead, the first source it hits that times out, I get the

perl Client-SSL-Warning: Peer certificate not verified

北城余情 提交于 2019-12-06 01:52:45
问题 I am having trouble with a perl screenscraper to an HTTPS site. In debugging, I ran the following: print $res->headers_as_string; and in the output, I have the following line: Client-SSL-Warning: Peer certificate not verified Is there a way I can auto-accept this certificate, or is that not the problem? #!/usr/bin/perl use LWP::UserAgent; use Crypt::SSLeay::CTX; use Crypt::SSLeay::Conn; use Crypt::SSLeay::X509; use LWP::Simple qw(get); my $ua = LWP::UserAgent->new; my $req = HTTP::Request-