Python crawl picture code how to write
This article mainly introduces the python crawl picture code how to write the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this python crawl picture code how to write the article will have a harvest, let's take a look at it.
Code display:
#! / usr/bin/env pythonimport urllib.requestfrom bs4 import BeautifulSoupdef crawl (url): headers = {'User-Agent':'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) Rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6'} req = urllib.request.Request (url, headers=headers) page = urllib.request.urlopen (req Timeout=20) contents = page.read () soup = BeautifulSoup (contents) my_girl = soup.find_all ('img') for girl in my_girl: link = girl.get (' src') print (link) content2 = urllib.request.urlopen (link). Read () with open (uprid:\ doubanmeizi'+'/'+link [- 11:], 'wb') as code: code.write (content2)
Page_start = 0page_stop = 10for page in range (page_start, page_stop): page + = 1 url = 'http://www.dbmeinv.com/?pager_offset=%s'% page crawl (url)
Print (", girls have finished downloading pictures!") This is the end of the article on "how to write python crawling picture code". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to write python crawling picture code". If you want to learn more knowledge, you are welcome to follow the industry information channel.