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 9229005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:27:59+00:00 2026-06-18T05:27:59+00:00

I am using urllib’s urlretrieve() function in Python in order to try to grab

  • 0

I am using urllib’s urlretrieve() function in Python in order to try to grab some pdf’s from websites. It has (at least for me) stopped working and is downloading damaged data (15 KB instead of 164 KB).

I have tested this with several pdf’s, all with no success (ie random.pdf). I can’t seem to get it to work, and I need to be able to download pdf’s for the project I am working on.

Here is an example of the kind of code I am using to download the pdf’s (and parse the text using pdftotext.exe):

def get_html(url): # gets html of page from Internet
    import os
    import urllib2
    import urllib
    from subprocess import call
    f_name = url.split('/')[-2] # get file name (url must end with '/')
    try:
        if f_name.split('.')[-1] == 'pdf': # file type
            urllib.urlretrieve(url, os.getcwd() + '\\' + f_name)
            call([os.getcwd() + '\\pdftotext.exe', os.getcwd() + '\\' + f_name]) # use xpdf to output .txt file
            return open(os.getcwd() + '\\' + f_name.split('.')[0] + '.txt').read()
        else:
            return urllib2.urlopen(url).read()
    except:
        print 'bad link: ' + url    
        return ""

I am a novice programmer, so any input would be great! Thanks

  • 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-18T05:28:00+00:00Added an answer on June 18, 2026 at 5:28 am

    I would suggest trying out requests. It is a really nice library that hides all of the implementation behind a simple api.

    >>> import requests
    >>> req = requests.get("http://www.mathworks.com/moler/random.pdf")
    >>> len(req.content)
    167633
    >>> req.headers
    {'content-length': '167633', 'accept-ranges': 'bytes', 'server': 'Apache/2.2.3 (Red Hat) mod_jk/1.2.31 PHP/5.3.13 Phusion_Passenger/3.0.9 mod_perl/2.0.4 Perl/v5.8.8', 'last-modified': 'Fri, 15 Feb 2008 17:11:12 GMT', 'connection': 'keep-alive', 'etag': '"30863b-28ed1-446357e3d4c00"', 'date': 'Sun, 03 Feb 2013 05:53:21 GMT', 'content-type': 'application/pdf'}
    

    By the way, the reason you are only getting a 15kb download is because your url is wrong. It should be

    http://www.mathworks.com/moler/random.pdf
    

    But you are GETing

    http://www.mathworks.com/moler/random.pdf/
    
    >>> import requests
    >>> c = requests.get("http://www.mathworks.com/moler/random.pdf/")
    >>> len(c.content)
    14390
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using urllib.urlretrieve in Python to download websites. Though some websites seem to
I found that you can't read from some sites using Python's urllib2(or urllib). An
I'm using urllib2 's urlopen function to try and get a JSON result from
I have started to learn how to scrape information from websites using urllib and
I want to download a file from a website using python (urllib or urllib2)
Hey, I'm having some trouble using the QuickBase API from Python. From the QuickBase
I tried to download something from the Internet using Python, I am using urllib.retriever
I'm using urllib (in Python) to fetch an SVG file: import urllib urllib.urlopen('http://alpha.vectors.cloudmade.com/BC9A493B41014CAABB98F0471D759707/-122.2487,37.87588,-122.265823,37.868054?styleid=1&viewport=400x231').read() which
I'd like to retrieve data from a specific webpage by using urllib library. The
I am using urllib.urlopen with Python 2.7 to read csv files located on an

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.