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:
import urllib2
resp = urllib2.urlopen("http://www.baidu.com")
print resp.read()
Get the web page as follows (beginning and end):
曾经蜡笔没有小新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