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 crawls the post bar picture and downloads

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

# cording = utf-8import urllib2import urllibimport reimport randomimport timedef get_url (url): Agent_list = ['Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36', "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1", "Mozilla/5.0 (X11)" CrOS i686 2268.111.0) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11 "] ip_list = ['123.169.165.255 User_agent = random.choice (Agent_list) httpproxy_handler = urllib2.ProxyHandler ({'http':random.choice (ip_list)}) opener = urllib2.build_opener (httpproxy_handler) urllib2.install_opener (opener) page = urllib2.Request (url) page.add_header (' User-Agent') User_agent) response = urllib2.urlopen (page) html = response.read () return html def down_img (html): reg = rascsrc = "(http:.+?\ .jpg) 'urlre = re.compile (reg) imglist = re.findall (urlre,html) for img in imglist: filename = img.split (" / ") [- 1] urllib.urlretrieve (img Filename,None) while True: url = raw_input ("Please enter the address of the post bar to download the picture:") if url = = Q: print ("run is terminated!") Break else: print ('start getting web information...') Get_url (url) print ('get web information successfully!') Print ('start downloading pictures...') Down_img (get_url (url)) print ('picture download complete!') Timesleep (3)

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

Servers

Wechat

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

12
Report