Python: Crawlers use Python to get all the pictures on the specified URL-jaosn niu

Source: Internet
Author: User
Tags define get

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.