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

  • Home
  • SEARCH
  • 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 3284454
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:09:23+00:00 2026-05-17T20:09:23+00:00

I wrote a web crawler in Python 2.6 using the Bing API that searches

  • 0

I wrote a web crawler in Python 2.6 using the Bing API that searches for certain documents and then downloads them for classification later. I’ve been using string methods and urllib.urlretrieve() to download results whose URL ends in .pdf, .ps etc., but I run into trouble when the document is ‘hidden’ behind a URL like:

http://www.oecd.org/officialdocuments/displaydocument/?cote=STD/CSTAT/WPNA(2008)25&docLanguage=En

So, two questions. Is there a way in general to tell if a URL has a pdf/doc etc. file that it’s linking to if it’s not doing so explicitly (e.g. http://www.domain.com/file.pdf)? Is there a way to get Python to snag that file?

Edit:
Thanks for replies, several of which suggest downloading the file to see if it’s of the correct type. Only problem is… I don’t know how to do that (see question #2, above). urlretrieve(<above url>) gives only an html file with an href containing that same url.

  • 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-05-17T20:09:23+00:00Added an answer on May 17, 2026 at 8:09 pm

    In this case, what you refer to as “a document that’s not explicitly referenced in a URL” seems to be what is known as a “redirect”. Basically, the server tells you that you have to get the document at another URL. Normally, python’s urllib will automatically follow these redirects, so that you end up with the right file. (and – as others have already mentioned – you can check the response’s mime-type header to see if it’s a pdf).

    However, the server in question is doing something strange here. You request the url, and it redirects you to another url. You request the other url, and it redirects you again… to the same url! And again… And again… At some point, urllib decides that this is enough already, and will stop following the redirect, to avoid getting caught in an endless loop.

    So how come you are able to get the pdf when you use your browser? Because apparently, the server will only serve the pdf if you have cookies enabled. (why? you have to ask the people responsible for the server…) If you don’t have the cookie, it will just keep redirecting you forever.

    (check the urllib2 and cookielib modules to get support for cookies, this tutorial might help)

    At least, that is what I think is causing the problem. I haven’t actually tried doing it with cookies yet. It could also be that the server is does not “want” to serve the pdf, because it detects you are not using a “normal” browser (in which case you would probably need to fiddle with the User-Agent header), but it would be a strange way of doing that. So my guess is that it is somewhere using a “session cookie”, and in the case you haven’t got one yet, keeps on trying to redirect.

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

Sidebar

Related Questions

No related questions found

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.