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