Crawling images of Python web crawler

Source: Internet
Author: User
Tags python web crawler

Today using requests and BeautifulSoup climbed some pictures, or very fulfilling, comments may be wrong, I hope you have more comments

ImportRequests fromBs4Importbeautifulsoupcircle= Requests.get ('Http://travel.quanjing.com/tag/12975/%E9%A9%AC%E5%B0%94%E4%BB%A3%E5%A4%AB')#put the acquired picture address into count in turnCount = []#put the acquired page content into BeautifulSoupSoup = BeautifulSoup (Circle.text,'lxml')#According to Google Selectgadget this plugin, get HTML tags, such as get: #gallery-list forIteminchSoup.select ('#gallery-list'):    #use the Find_all in the BS4 to get #gallery if there is an IMG tag in the-list     forImginchItem.find_all ('img'):        Print('img', IMG)#m is an attribute that exists in the IMG tagImg_path = Img.get ('m') count.append (Img_path)#use enumerate to remove the image address in count to put in V forI,vinchEnumerate (count):#put the obtained V value into the request again to the site corresponding toImage =Requests.get (v)#in the process of accessing the picture, the type of int cannot be stored, so we convert it to STR (). W: Read and write mode open, B: binary to read and write. Images are generally used in binary. With open ('d:\\img'+str (i) +'. jpg','WB') as file:#content: Images are converted to binary and saved. file.write (image.content)Print(i)

Crawling images of Python web crawler

Related Article

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.