首页 > 代码库 > 【Python】下载图片
【Python】下载图片
import requests import bs4 import urllib.request import urllib import os hdr = {‘User-Agent‘: ‘Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11‘, ‘Accept‘: ‘text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8‘, ‘Accept-Charset‘: ‘ISO-8859-1,utf-8;q=0.7,*;q=0.3‘, ‘Accept-Encoding‘: ‘none‘, ‘Accept-Language‘: ‘en-US,en;q=0.8‘, ‘Connection‘: ‘keep-alive‘} DownPath = "C:/Users/Administrator/PycharmProjects/untitled/" c = ‘.jpg‘ for x in range(5, 100): newDownPath = DownPath + str(x) +"/" os.mkdir(newDownPath) site = "http://www.meizitu.com/a/" + str(x) + ".html" local_filename, headers = urllib.request.urlretrieve(site) html = open(local_filename) soup = bs4.BeautifulSoup(html,"html5lib") jpg = soup.find_all(‘img‘) PhotoNum = 0 for photo in jpg: src = http://www.mamicode.com/photo.get(‘src‘)>
【Python】下载图片
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。