Sunday 15 March 2015

python - How to print raw html string using urllib3? -


To get the Html string, I use the statement below:
  import urllib3 url =  

'http: //urllib3.readthedocs.org / 'Http_pool = urllib3.connection_from_url (url) r = http_pool.urlopen (' GET ', url) print (r.data)

but the output is:

  b '& lt ;! DOCTYPE html public "- // W3C // DTT XHTML 1.0 Stronger // N" B "\ n & lt ;! DOCTYPE HTML Public" - // W3C / DTD XHTML 1.0 Transcription / N "\ n" http: //www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n\n\n<html Xmlns = "http://www.w3.org/1999/xhtml" & gt; \ N & lt; head & gt; \ n & lt; meta-http-equiv = "content-type" content = "text / html; Charset = utf-8 "/> \ n \ n \ n .................................. .... \ n & lt; / script & gt; \ n \ n \ n \ n & lt; / body & gt; \ n & lt; / html & gt; ''   

How do I get a raw HTML string?

anwser is print (r) .data.decode ('utf-8'))
But this statement will break into sublime text 2. Because of the


When I use IDEL, the output is OK

No comments:

Post a Comment