import urllib2 import filecmp
def url_open(url): response=urllib2.urlopen(url) html=response.read() f=open('f:\python\url_open.txt','w') f.write(html) f.close()
def url_request(url): req=urllib2.Request(url) response=urllib2.urlopen(req) the_page=response.read() f=open('f:\python\url_request.txt','w') f.write(the_page) f.close
def compare(): return filecmp.cmp(r'f:\python\url_open.txt',r'f:\python\url_request.txt')
if __name__=='__main__': url="" url_open(url) url_request(url) res=compare() print res
|
Compare the difference of the file get by using request and using urlopen directly.
阅读(740) | 评论(0) | 转发(0) |