Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python crawl picture code how to write

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report