Python urllib2.urlopen(url).read() is different from source code seen in Firefox

208 views Asked by At

When I use urllib2.urlopen(url).read() I read a source code slightly different from what I read in Firefox. In source code seen in Firefox some special characters, such as quotation marks ("), apostrophe ('), etc are converted to %22, %27 etc.

When I use urllib2.urlopen(url).read(), special characters are readable in clear text. I would like to see the source code of a web page with Python as I see it with Firefox (with% 22,% 27, etc).

Thank you and sorry for my english.

1

There are 1 answers

1
Julio Daniel Reyes On

Perhaps that is urlencoded.

You can try to escape the result.

data = urllib2.urlopen(url).read()
print(urllib.quote(data))