Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python's .text : Couldn't get it to work

Tags:

python

I've been trying to get the .text thingy in Python which converts html codes into readable text to work but still no luck.

Let's say I have the following code :

import urllib

url = ['http://google.com','http://bing.com']

for i in url:
    html = urllib.urlopen(i).read()
    print html.encode('utf-8').text

The code works once I remove the .text in the last line but I've seen people using that in tutorials without any problem at all. Any idea why couldn't I get it to work ? lol

Thank you very much !

like image 538
E-Law Avatar asked Jan 30 '26 01:01

E-Law


1 Answers

import urllib

url = ['http://google.com','http://bing.com']

for i in url:
    html = urllib.urlopen(i).read()
    print html

No need for encode or text, just can print the html write after read(). I would suggest that you use python-requests.

like image 165
Games Brainiac Avatar answered Feb 01 '26 14:02

Games Brainiac