LWP set max_size but still get content

为君一笑 提交于 2019-12-11 09:34:37

问题


I am using LWP to get the content from some sites and whenever the page size is larger than one megabyte, I would like LWP to stop downloading the page. This is accomplished with this code:

my $ua = LWP::UserAgent->new;
$ua->max_size(1024);

And it works fine. The only problem is that even when the page is over 1mb, I would still like to be able to get the content of what it has downloaded so far. However, whenever I do this (the traditional way to get content with LWP when there are no errors):

$ua->content;

It seems to not be the actual page's content but a bunch of nonsense. Does anyone know of a way to set max_size and still get whatever was downloaded before it hit the limit with LWP or even WWW::Mechanize? Thanks a lot!

来源:https://stackoverflow.com/questions/10989684/lwp-set-max-size-but-still-get-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!