search

Home  >  Q&A  >  body text

python2.7 urllib2 obtains incomplete display of web pages

I used the urllib2 module in python2.7 to write a very simple code to obtain the source code of the web page, but the source code of the returned web page only has the lower half, such as </html></body> and other concluding words. , but there is no code in the upper part such as <!doctype><html>. I hope someone can help me. Thank you. The code is as follows:

coding:utf-8

import urllib2
resp = urllib2.urlopen("http://www.baidu.com")
print resp.read()
Get the web page as follows (beginning and end):

習慣沉默習慣沉默2756 days ago914

reply all(1)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-18 11:03:12

    The code is fine, the problem is the command window. resp.read() obtains all the content, but the command window is not fully displayed.
    python test.py > res.txt Output to file for viewing

    reply
    0
  • Cancelreply