Get the App
SLTechnology News&Howtos  ›  Servers  › 

Python crawls the post bar picture and downloads

Shulou Source: shulou.com Published: 2022-06-03 09:18:24 09月30日 Update

# 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)

Tags: Picture information web page post bar success picture download address input run Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MariaDB MySQL Shulou Information Redmi