上代码:
1 import requests,urllib.request 2 from bs4 import BeautifulSoup 3 url = 'http://photo.bitauto.com/' 4 header = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 UBrowser/5.7.16173.12 Safari/537.36'} 5 source_code = requests.get(url,headers = header) 6 # print (source_code) 7 plain_text = source_code.text 8 # print (plain_text) 9 Soup = BeautifulSoup(plain_text) 10 # print (Soup) 11 download_link = [] 12 folder_path = 'F:/pictures_py/cars/' 13 for pic_tag in Soup.find_all('img'): 14 pic_link = pic_tag.get('src') 15 download_link.append(pic_link) 16 # print (download_link) 17 for item in download_link: 18 urllib.request.urlretrieve(item,folder_path + item[-10:]) 19 print ('done')