#CODING=GBKImporturllib.requestImportReImportOSImportUrllibdefgethtml (URL):#Specify URL fetch functionpage =urllib.request.urlopen (URL) HTML=Page.read ()returnHtml.decode ('UTF-8')defGetimg (HTML):#define get Picture functionReg = R'src= "(. +?\.jpg)" Pic_ext'Imgre=Re.compile (reg) Imglist=Imgre.findall (HTML) x=0 Path= R'F:\File_Python\Crawler' #Save the picture to the F:\File_Python\Crawler folder, and if there is no crawler folder, it will be created automatically if notOs.path.isdir (path): os.makedirs (path) Paths= path+'\\' forImgurlinchImglist:#Open the Imgurl image URL saved in the In collection, and loop to download the picture saved locallyUrllib.request.urlretrieve (Imgurl,'{}{}.jpg'. Format (paths,x)) x= x + 1returnimglisthtml= Gethtml ("https://tieba.baidu.com/p/2460150866?pn=10")#Specify the URL path to get the picturePrint(getimg (HTML))
Python: Crawlers use Python to get all the pictures on the specified URL-jaosn niu