python批处理实现爬取网页静态图片文件重命名图片统一修改大小等功能
来源:互联网 发布:php mysql 存储过程 编辑:程序博客网 时间:2024/06/04 23:09
按照特定字符(此处选为字符’j’)分割文档成多个小文档
def main(): with open("dir/origin.txt","r") as f: temp = f.readlines() words = [] L = len(temp) for i in range(L): if "j" in temp[i] : words = temp[i] with open('dir/'+words[0:6]+'.txt', 'w') as g: for j in range(i+1, L): if "j" in temp[j]: break g.write(temp[j])if __name__ == '__main__': main()
爬取网页静态图片
###coding=utf-8#####urllib模块提供了读取Web页面数据的接口##import urllib.request###re模块主要包含了正则表达式##import re###定义一个getHtml()函数##def getHtml(url):## page = urllib.request.urlopen(url) #urllib.urlopen()方法用于打开一个URL地址## html = page.read() #read()方法用于读取URL上的数据## return html####def getImg(html):## reg = r'src="(.+?\.jpg)" pic_ext' #正则表达式,得到图片地址## imgre = re.compile(reg) #re.compile() 可以把正则表达式编译成一个正则表达式对象.## imglist = re.findall(imgre,html) #re.findall() 方法读取html 中包含 imgre(正则表达式)的 数据## #把筛选的图片地址通过for循环遍历并保存到本地## #核心是urllib.urlretrieve()方法,直接将远程数据下载到本地,图片通过x依次递增命名## x = 0#### for imgurl in imglist:## urllib.request.urlretrieve(imgurl,'/Users/c-ten/Desktop/worm/%s.jpg' % x)## x+=1######html = getHtml("http://image.baidu.com/search/index?tn=baiduimage&ct=201326592&lm=-1&cl=2&ie=gbk&word=masked%20faces&hs=2&xthttps=000000&fr=ala&ori_query=masked%20faces&ala=0&alatpl=sp&pos=0")###print getImg(html)#<span style="color:#330099;">'''#Created on 2017-4-17#@author: Administrator#'''import urllib.requestimport redef gethtml(url): html=urllib.request.urlopen(url) data=html.read() return data.decode("utf-8")def getimg(html): dir="/Users/c-ten/Desktop/worm/" #图片保存路径 reg='src="(.+?\.jpg)" pic_ext' imgreg=re.compile(reg) imglist=imgreg.findall(html) x=0 for i in imglist: print(i) urllib.request.urlretrieve(i,'{}{}.jpg'.format(dir, x)) x=x+1print('gethtml')html=gethtml("http://image.baidu.com/search/index?tn=baiduimage&ct=201326592&lm=-1&cl=2&ie=gbk&word=%BF%DA%D5%D6%C3%B1%D7%D3%D5%DA%B5%B2%C8%CB%C1%B3%CD%BC%C6%AC&hs=2&xthttps=000000&fr=ala&ori_query=%E5%8F%A3%E7%BD%A9%E5%B8%BD%E5%AD%90%E9%81%AE%E6%8C%A1%E4%BA%BA%E8%84%B8%E5%9B%BE%E7%89%87&ala=0&alatpl=sp&pos=0")print('getimg')getimg(html)#</span><span style="color:#333333;">#</span>
计算文档行数
def main(): with open("list.txt","r") as f: temp = f.readlines() L = len(temp) print(L) f.close()if __name__ == '__main__': main()
批量增加后缀名
# -*- coding: cp936 -*-import ospath = 'jpg_files_dir'for file in os.listdir(path): if os.path.isfile(os.path.join(path,file))==True: if file.find('.')<0: newname=file+'.jpg' os.rename(os.path.join(path,file),os.path.join(path,newname))
阅读全文
1 0
- python批处理实现爬取网页静态图片文件重命名图片统一修改大小等功能
- Python爬虫---爬取静态网页的图片
- python爬取网页图片
- python爬取网页图片
- Python爬取网页图片
- Python爬取网页图片
- Python 爬取网页图片
- Python 网页爬取图片
- Python 实现爬取图片
- 【Python】pdf文件逐页转图片/修改图片存储大小脚本
- 用python 爬取网页图片
- Python爬取一个网页的图片
- Python入门-爬取网页图片
- 使用Python爬取网页图片
- 利用python爬取网页图片
- Python爬取一个网页的图片
- Python爬取网页图片01
- Python爬取网页图片02
- POJ 2709 染料问题
- 进程
- ffmpeg工具调研
- 对lf_feature_storage性能测试分析(c测试用例版)
- [.cpp]统计双拼拼音一种方案的重码数
- python批处理实现爬取网页静态图片文件重命名图片统一修改大小等功能
- 剑指offer——反转单词顺序列
- Idea 部署非Maven Web工程
- 【android基础开发】省钱达人UI—初级开发练手的好代码
- 四舍五入与进一法
- 【题目】:输入一个非负整形数组,其中每个数代表紧挨着的宽为1的墙的高度,输出这些墙之间能积水的体积。函数接口为 int Volume(int * height,int n),要求只能遍历一 遍数组,且
- iperf 移植并与WIN10之间测wifi
- 安卓常用的开源第三方库
- shiro默认filter