python 3中urlretrieve方法直接将远程数据下载到本地.为什么不行? 55

import re import urllib.request def getHtml(url): page = urllib.request.urlopen(url) html = page.read() return html def getImg(html): html = html.decode('GBK') reg = r'src="(.*?\.jpg)" width'... 展开

 

默_____契 | 浏览 20538 次 |举报

我有更好的答案
 
2018-02-02

 

最佳答案

 

你的路径可能不对,按照我的代码,你需要在d盘根目录下新建一个test文件夹,才能正常运行

我把代码附上:

import re
import urllib.request
 
def Schedule(a,b,c):
       per = 100.0 * * / c
       if per>100:
           per = 100
           print('完成!')
       print('%.2f%%' % per)
def getHtml(url):
       page = urllib.request.urlopen(url)
       html = page.read()
       return html
 
def getImg(html):
       html = html.decode('utf-8')
       reg = r'src="(.*?\.jpg)" width'
       imgre = re.compile(reg)
       imglist = imgre.findall(html)
       = 0
       for imgurl in imglist:
              #  写好你的路径
              urllib.request.urlretrieve(imgurl,'D:\\test\\%s.jpg' % x,Schedule)
              += 1
 
html = getHtml('http://tieba.baidu.com/p/741081023')
print(getImg(html))

运行结果:

python urlretrieve 下载图片的更多相关文章

  1. 用python批量下载图片

    一 写爬虫注意事项 网络上有不少有用的资源, 如果需要合理的用爬虫去爬取资源是合法的,但是注意不要越界,前一阶段有个公司因为一个程序员写了个爬虫,导致公司200多个人被抓,所以先进入正题之前了解下什么 ...

  2. python——批量下载图片

    前言 批量下载网页上的图片需要三个步骤: 获取网页的URL 获取网页上图片的URL 下载图片 例子 from html.parser import HTMLParser import urllib.r ...

  3. python 爬虫 下载图片

    import os#导入操作系统模块from urllib.request import urlretrieve#下载url对应的文件from urllib.request import urlope ...

  4. python 爬虫--下载图片,下载音乐

    #下载图片 imgUrl='http://www.pptbz.com/pptpic/UploadFiles_6909/201211/2012111719294197.jpg' r=requests.g ...

  5. python 批量下载图片

    #coding=utf-8import re,sysimport urllib def getHtml(url): page = urllib.urlopen(url) html = page.rea ...

  6. python批量下载图片

    从数据库拿了一批图片地址,需要一张一张的把图片下载下来,自从有了python,想到能省事就琢磨如何省事. 代码如下: import urllib.requestf=open("E:\999\ ...

  7. python批量下载图片的三种方法

    一是用微软提供的扩展库win32com来操作IE: win32com可以获得类似js里面的document对象,但貌似是只读的(文档都没找到). 二是用selenium的webdriver: sele ...

  8. python requests下载图片

    # 文件下载方法 from urllib.request import urlretrieve import requests # 第一 urlimage = 'https://www.python. ...

  9. python正则下载图片

    import urllib.request import re # 打开图片路径 def open_url(url): #设置请求路径 req = urllib.request.Request(url ...

随机推荐

  1. 拒绝了对对象 '****'(数据库 '******',所有者 '***')的 SELECT 权限

    数据库(xxx) --->安全性---->架构---->dbo(属性)--->权限--->添加--->浏览-->public 添加 select 等您需要的权 ...

  2. Ubuntu 18.10连接Windows 桌面

    ========================= 适用于Linux连接Windows远程桌面 Linux版本:CentOS.Ubuntu等 1.终端命令安装远程桌面客户端工具,具体命令如下: sud ...

  3. hdu5230

    bc41第三题: 由 1 - n-1 这 n-1 个数组成 l - c 到 r - c 闭区间内的数共有多少种组合方法: 据称本来应该也比较简单吧,xiaoxin说了个五边形数,然后纷纷找了五边形数的 ...

  4. FabricExpress.net supply high quality quilting fabric

    FabricExpress is a company specializing in high quality custom t-shirts,custom fabric,senior handmad ...

  5. stenciljs ionic 团队开发的方便web 组件框架

    stenciljs 是ionic 团队开发的方便组件话开发的js 框架,具体以下特点 简单,零配置,简单的api,typescript 支持 性能,压缩之后6Kb,支持ssr,以及强大的原生web c ...

  6. 将svnserve部署为后台服务

    由于svnserve运行模式没有部署为后台服务,很容易被人误关掉.于是在网上查了一下,发现也已经有人总结了.Copy过来,以作备忘. 以前的svnserve要想成为windows服务,必须依赖于svn ...

  7. TweenMax.allTo

    需要多个MC进行相同的缓动.比如下面这个游戏菜单.三个按钮的缓动是相同的,都缓动到同一个x坐标位置.然后同时有缓动出舞台. 如果有TweenLite实现的话,需要             if (is ...

  8. Centos安装git2.2.1

    由于Centos6.5使用yum -y install git 安装的git版本是 git --versiongit version 1.7.1 想要升级到2.2.1: ># yum remov ...

  9. vue-cli 知识点

    vue init webpack [project_name] 构建的项目,新增功能需要做的工作: table th:first-of-type { width: 100px; } table th: ...

  10. SQL Server Reporting Service 报错:报表服务器无法解密用于访问报表服务器数据库中的敏感数据或加密数据的对称密钥,必须还原备份密钥或删除所有加密的内容。

    出现这个问题,可以通过reporting services 配置管理工具来处理 首先,打开配置管理工具,连接. 在左侧的导航选项中选择Encryption Keys,将出现如图所示的界面,在右侧点击d ...