Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8299879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:19:44+00:00 2026-06-08T16:19:44+00:00

I want my script to download only text/html content and not binary or images

  • 0

I want my script to download only text/html content and not binary or images that could take significantly more time to download. I know about the max_size parameter but I would like to add a check on the Content-Type header. Is this doable ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T16:19:45+00:00Added an answer on June 8, 2026 at 4:19 pm

    As pointed out by others you can perform a HEAD request before your GET request. You ought to do this as a way of being polite to the server because it actually is easy for you to abort the connection, but not necessarily easy for the web server to abort sending a bunch of data and doing a bunch of work on its end.

    There are some different ways to do this depending on how sophisticated you want to be.

    1. You can send an Accept header with your request which only lists text/html. A well-implemented HTTP server will return a 406 Not Acceptable status if you say you don’t accept whatever it is the file is. Of course, they might send it to you anyway. You can do this as your HEAD request as well.

    2. When using a recent version of LWP::UserAgent, you can use a handler subroutine to abort the rest of the request after the headers and before the content body.

      use LWP::UserAgent;
      use Try::Tiny; 
      
      my $ua = LWP::UserAgent->new;
      $ua->add_handler( response_header => sub {
          my($response, $ua, $h) = @_;
      
          die "Not HTML" unless $response->content_type eq 'text/html';
      });
      
      my $url = "http://example.com/foo";
      
      my $html;
      my $head_response = $ua->head($url, Accept => "text/html");
      if ($head_response->is_success) {
          my $get_response = $ua->get($url, Accept => "text/html");
          if ($get_response->is_success) {
              $html = $get_response->content;
          }
      } 
      

    See the Handlers section of the LWP::UserAgent documentation for details on handlers.

    I haven’t caught the exception thrown or made sure to deal with the 406 responses carefully here. I leave that as an exercise for the reader.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: I´ll be more specific. I want to do a script to download a
I want to script the download of messages from hotmail. Both Gmail and Hotmail
I got a problem with JavaScript. I want a script that will pop-up on
I'm trying to write a bash script that will let me download multiple web
I guess I want to ultimately build out a script that will force the
I want to write a python script which downloads the web-page only if the
I want to execute some javascript which is part of html I download through
I'm writing my first CI script using MSBuild and I want to everyone that
I have a php script that limits the amount of times people can download
I'm writing a script in Python that saves attachments from Gmail, only from unseen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.