6

以下のステートメントを使用して、html 文字列を取得します。

import urllib3

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

print (r.data)

しかし、出力は次のとおりです。

b'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "b'\n<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\n  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n\n\n<html xmlns="http://www.w3.org/1999/xhtml">\n  <head>\n    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />\n    \n\n   .......................................\n</script>\n\n\n\n  </body>\n</html>''

生のhtml文字列を取得するにはどうすればよいですか?

4

1 に答える 1

7

答えはprint (r.data.decode('utf-8'))
But this statement will break in sublime text 2.
because of this issue .
IDLEを使用すると、出力は問題ありません。

于 2013-06-23T05:53:28.600 に答える