How can I screen scrape with Perl?

前端 未结 10 845
夕颜
夕颜 2020-12-13 23:28

I need to display some values that are stored in a website, for that I need to scrape the website and fetch the content from the table. Any ideas?

10条回答
  •  误落风尘
    2020-12-13 23:48

    I use LWP::UserAgent for most of my screen scraping needs. You can also Couple that with HTTP::Cookies if you need Cookies support.

    Here's a simple example on how to get source.

    use LWP;
    use HTTP::Cookies;
    my $cookie_jar = HTTP::Cookies->new;
    my $browser = LWP::UserAgent->new;
    $browser->cookie_jar($cookie_jar);
    
    $resp = $browser->get("https://www.stackoverflow.com");
    if($resp->is_success) {
       # Play with your source here
       $source = $resp->content;
       $source =~ s/^.*/
    /i; # this is just an example print $source; # not a solution to your problem. }

    提交回复
    热议问题