python批量下载
# -*- coding: utf-8 -*-
__author__ = 'Administrator'
from PyQt4.Qt import *
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import sys,os,datetime,urllib,urllib2,re,threading,thread
from g1 import Ui_Form
class Gui2(QDialog,Ui_Form):
def __init__(self):
super(Gui2,self).__init__()
self.setupUi(self)
self.UrlCount.setReadOnly(True)
t=QTimer(self)
t.timeout.connect(self.datetimes)
t.start(1000)
self.pushSelect.clicked.connect(self.FilePath)
self.UrlFile.setText(r'\pic')
self.DownButton.clicked.connect(download)
def getWebsite(self):
return self.UrlEdit.text() #获取网址的函数
def getFilePath(self):
return self.UrlFile.text() #获取文件路径的函数
def setTag(self,downloadtag):
self.UrlCount.setText(downloadtag) #显示状态
def FilePath(self):
filepath=QFileDialog.getExistingDirectory(self,'select','/pic')
self.UrlFile.setText(unicode(filepath))
while True:
if (filepath.isEmpty()):
QMessageBox.information(self,'Error','Error')
filepath=QFileDialog.getExistingDirectory(self,'select','/')
continue
else:self.UrlFile.setText(unicode(filepath))
break
def datetimes(self):
self.UrlTime.setText(datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
def download():
Wb=unicode(main.getWebsite(),'utf-8').encode('utf-8')
Fp=main.getFilePath()
main.setTag('ok')
t=MyT(Wb,Fp)
t.start()
class MyT(threading.Thread):
def __init__(self,web,files):
threading.Thread.__init__(self)
self.web=web
self.files=files
def run(self):
html=getHttl(self.web)
print self.web
print self.files
getImg(html,self.files)
main.setTag('ok')
def getHttl(url):
return urllib.urlopen(url).read() #返回网页源码
def getImg(html,path):
reg=re.compile(r'src="(.*?\.(jpg|gif|png|js))')
imglist=reg.findall(html)
print len(imglist)
x=1
for imgurl in imglist:
print imgurl
main.setTag(str(x)+'/'+str(len(imglist))) #在状态栏上显示进度
if imgurl[1]=='gif':
xpath=path+'\%d.gif' % x
urllib.urlretrieve(imgurl[0],xpath)
elif imgurl[1]=='png':
xpath=path+'\%d.png' % x
urllib.urlretrieve(imgurl[0],xpath)
elif imgurl[1]=='js':
xpath=path+'\%d.js' % x
urllib.urlretrieve(imgurl[0],xpath)
else:
xpath=path+'\%d.jpg' % x
urllib.urlretrieve(imgurl[0],xpath)
x+=1
print 'finish--------'
app=QApplication(sys.argv)
main=Gui2()
main.show()
sys.exit(app.exec_())
文件:http://url.cn/XDattY
python批量下载的更多相关文章
- 用Python批量下载DACC的MODIS数据
本人初次尝试用Python批量下载DACC的MODIS数据,记下步骤,提醒自己,数据还在下载,成功是否未知,等待结果中...... 若有大佬发现步骤有不对之处,望指出,不胜感激. 1.下载Python ...
- python批量下载微信好友头像,微信头像批量下载
#!/usr/bin/python #coding=utf8 # 自行下载微信模块 itchat 小和QQ496631085 import itchat,os itchat.auto_login() ...
- 用python批量下载贴吧图片 附源代码
环境:windows 7 64位:python2.7:IDE pycharm2016.1 功能: 批量下载百度贴吧某吧某页的所有帖子中的所有图片 使用方法: 1.安装python2.7,安装re模块, ...
- 用python批量下载图片
一 写爬虫注意事项 网络上有不少有用的资源, 如果需要合理的用爬虫去爬取资源是合法的,但是注意不要越界,前一阶段有个公司因为一个程序员写了个爬虫,导致公司200多个人被抓,所以先进入正题之前了解下什么 ...
- Python 批量下载BiliBili视频 打包成软件
文章目录 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手.很多已经做案例的人,却不知道如何去学习更加高深的知识.那么针对这三类人,我给大家 ...
- python——批量下载图片
前言 批量下载网页上的图片需要三个步骤: 获取网页的URL 获取网页上图片的URL 下载图片 例子 from html.parser import HTMLParser import urllib.r ...
- Python - 批量下载 IIS 共享的文件
1.说明 用 IIS 以WEB形式发布了本地文件夹,提供文件下载,并设置了访问权限:默认下载需要点击一个一个的下载,web界面如下: 3.脚本 执行脚本批量下载文件,会在当前目录创建文件夹,并压缩该文 ...
- python批量下载图片的三种方法
一是用微软提供的扩展库win32com来操作IE: win32com可以获得类似js里面的document对象,但貌似是只读的(文档都没找到). 二是用selenium的webdriver: sele ...
- 使用Python批量下载Plus上的Podcast
Plus是一个介绍数学之美与实际应用的网络杂志,其中包含了数学知识.轶闻趣事.历史典故等许多精彩的内容.该杂志恰好有一个Podcast栏目,提供了不少采访与讲座的mp3音频.于是, 我使用Python ...
- python 批量下载图片
#coding=utf-8import re,sysimport urllib def getHtml(url): page = urllib.urlopen(url) html = page.rea ...
随机推荐
- 获取当前位置信息-ios
locationManager= [[CLLocationManager alloc] init];//位置管理器 locationManager.desiredAccuracy = kCLLocat ...
- Ubuntu Wpa wifi connection
最近做一个项目,需要做一个WIFI连接模块,这几天都在折腾,终于,今天终于是连上网络了,只不过连网的过程有点慢,还有一些缺点,先写下来以备忘记. 1.环境建立: sudo apt-get instal ...
- mysql常用操作 mysql备份与恢复
先登录mysql ==>mysql -uroot -p 查看数据库的版本 select version(); 查看有哪些库 show datases; 查看当前处于哪个库 select da ...
- Solr集成IK中文分词器
1.将IKAnalyzer-2012-4x.jar拷贝到example\solr-webapp\webapp\WEB-INF\lib下: 2.在schema.xml文件中添加fieldType: &l ...
- js中substring/substr和C#中Substring的用法
一:在js中截取字符串的方法有两个:substring和substr 1.方法: substring(int stringIndex,[int endIndex]) 截取从索引为stringIndex ...
- displaytag 简单使用流程
1. 首先导入包:displaytag-1.2.jar,commons-lang.jar和standard.jar;commons-beanutils.jar;这四个jar包 2. 然后在jsp页面做 ...
- 网络NSURLSession
简单下载图片 dispatch_queue_t queue =dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT); dispatch_asyn ...
- 闭包中的 this 对象
关于this对象 在闭包中使用this对象也可能会导致一些问题.this对象是在运行时基于函数的执行环境绑定的:在全局函数中,this等于window, function createFunction ...
- C++ Primer 5th 第3章 字符串、向量和数组
*****代码在Debian g++ 5.40 / clang++ 3.8(C++11)下编写调试***** 本章主要是关于字符串.数组的内容,以及一些简单的容器知识. 1.using的声明 usin ...
- web标准(复习)--8
今天我们开始学习下拉及多级弹出菜单,包含以下内容和知识点: 带下拉子菜单的导航菜单 绝对定位和浮动的区别和运用 css自适应宽度滑动门菜单 一.带下拉子菜单的导航菜单下拉菜单在一些企业网站应用尤为广泛 ...