1

I have this code snippet as part of python code to crawl a particular website (see the code below). But to my surprise the output code is not an html. I am using python 3.4

   import urllib.request as ur
   user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
   headers = { 'User-Agent' : user_agent }

   s = ur.urlopen('http://www.nairaland.com')
   pl = s.read()
   print(pl) 

My output from this code is:

b''

rather than the expected html code. Please guide me towards getting this code work. I need the html code in another part of the code. Thanks in advance.

1 Answer 1

1

The excellent requests library returns the correct HTML:

import requests
s = requests.get('http://www.nairaland.com')
pl = s.text
print(pl)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.