This article has shared the specific code for python saving web page pictures to local. For your reference, the specific content is as follows
#!/usr/bin/env Python #coding=utf-8 import time import datetime import sys import random import math import uuid import cookielib import urllib2 import os class GetImage(): reload(sys) ('utf8') ''' Crawl the content of the web page file and save it to memory @url To grab the file, path+filename ''' def get_file(self,url): try: cj=() opener=urllib2.build_opener((cj)) urllib2.install_opener(opener) req=(url) operate=(req) data=() return data except BaseException, e: print e return None ''' Save the file locally @path Local path @file_name File name @data File content ''' def save_file(self,file_name, data): if data == None: return file=open(file_name, "wb") (data) () () def save_png_file(self,filename,url): self.save_file(filename,self.get_file(url)) if __name__=="__main__": h1 = GetImage() #h1.save_file('c:/log/',h1.get_file('http://1.1.1.1/doc/images/public/ICON/')) #url = 'http://1.1.1.1/doc/images/public/ICON/' #file_path ='c:/log/' #h1.save_png_file(file_path,url)
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.