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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:01:04+00:00 2026-06-12T01:01:04+00:00

I’m writing a crawler to download the static html pages using urllib . The

  • 0

I’m writing a crawler to download the static html pages using urllib.

The get_page function works for 1 cycle but when i try to loop it, it doesn’t open the content to the next url i’ve fed in.

  • How do i make urllib.urlopen continuously download HTML pages?
  • If it is not possible, is there any other suggestion to download
    webpages within my python code?

my code below only returns the html for the 1st website in the seed list:

import urllib
def get_page(url):
    return urllib.urlopen(url).read().decode('utf8')

seed = ['http://www.pmo.gov.sg/content/pmosite/home.html', 
            'http://www.pmo.gov.sg/content/pmosite/aboutpmo.html']    

for j in seed:
      print "here"
      print get_page(j)

The same crawl “once-only” problem also occurs with urllib2:

import urllib2
def get_page(url):
    req = urllib2.Request(url)
    response = urllib2.urlopen(req)
    return response.read().decode('utf8')

seed = ['http://www.pmo.gov.sg/content/pmosite/home.html', 
            'http://www.pmo.gov.sg/content/pmosite/aboutpmo.html']    

for j in seed:
      print "here"
      print get_page(j)

Without the exception, i’m getting an IOError with urllib:

Traceback (most recent call last):
  File "/home/alvas/workspace/SingCorp/sgcrawl.py", line 91, in <module>
    print get_page(j)
  File "/home/alvas/workspace/SingCorp/sgcrawl.py", line 4, in get_page
    return urllib.urlopen(url).read().decode('utf8')
  File "/usr/lib/python2.7/urllib.py", line 86, in urlopen
    return opener.open(url)
  File "/usr/lib/python2.7/urllib.py", line 207, in open
    return getattr(self, name)(url)
  File "/usr/lib/python2.7/urllib.py", line 462, in open_file
    return self.open_local_file(url)
  File "/usr/lib/python2.7/urllib.py", line 476, in open_local_file
    raise IOError(e.errno, e.strerror, e.filename)
IOError: [Errno 2] No such file or directory: 'http://www.pmo.gov.sg/content/pmosite/aboutpmo.html'

Without the exception, i’m getting a ValueError with urllib2:

Traceback (most recent call last):
  File "/home/alvas/workspace/SingCorp/sgcrawl.py", line 95, in <module>
    print get_page(j)
  File "/home/alvas/workspace/SingCorp/sgcrawl.py", line 7, in get_page
    response = urllib2.urlopen(req)
  File "/usr/lib/python2.7/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib/python2.7/urllib2.py", line 392, in open
    protocol = req.get_type()
  File "/usr/lib/python2.7/urllib2.py", line 254, in get_type
    raise ValueError, "unknown url type: %s" % self.__original
ValueError: unknown url type: http://www.pmo.gov.sg/content/pmosite/aboutpmo.html

ANSWERED:

The IOError and ValueError occurred because there was some sort of Unicode byte order mark (BOM). A non-break space was found in the second URL. Thanks for all your help and suggestion in solving the problem!!

  • 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-12T01:01:05+00:00Added an answer on June 12, 2026 at 1:01 am

    Both of your examples work fine for me. The only explanation I can think of for your exact errors is that the second URL string contains some sort of non-printable character (a Unicode BOM, perhaps) that got filtered out when pasting the code here. Try copying the code back from this site into your file, or retyping the entire second string from scratch.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to construct a data frame in an Rcpp function, but when I
I have thousands of HTML files to process using Groovy/Java and I need to
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.