python 抓取网页

import urllib
import os

print "downding..."

http = urllib.urlopen('http://www.baidu.com')
file=open("test.html","w")

if http.code ==200:
    print "donwload succ"

while 1:
    str=http.read(1024)
    if not len(str):
        break
    file.write(str)

	
print http.info()  

file.close()
http.close()

if not len(str): 
    print "download done"
else:
    print "download error"

os.system("test.html")  




原文地址:https://www.cnblogs.com/foxhengxing/p/2092819.html