#import requests import urllib import re #res = requests.get('https://www.douban.com/') #res = urllib.urlopen('https://www.douban.com').read() #web url 1 res = urllib.urlopen('https://www.douban.com/location/wuhan/events/week-all').read() #web url 2 down_path = r'C:\liujwFiles\NON_IBM_Files\PycharmProjects\pa_chong_files' # r : current characters will not be transferred meaning #reg = r'data-origin="(.*?)"' # key words1 reg = r'data-lazy="(.*?)"' # key words2 url_list = re.findall(reg, res) download_count = len(url_list) print "Begin to download files.........there are %i files in total....." % download_count for url in url_list: try: #There are 2 types of image url format: #data - origin = "https://img3.doubanio.com/mpic/s29494781.jpg" #data-origin="https://img3.doubanio.com/view/ark_article_cover/large/public/35300210.jpg?v=1499854173.0" image_name = url.split('/')[-1].split('?')[0] urllib.urlretrieve(url, '%s\download_img.%s' % (down_path, image_name)) except IOError: print "File %s download failed......." % url.split('/')[-1] download_count = download_count - 1 print "Download complete! %i files download successfully" % download_count
Python 爬虫爬取图片(未分页)
最新推荐文章于 2023-11-04 16:13:50 发布