有些冗余信息。由于之前測试正則表達式。所以没有把它们给移走。只是不影响使用。

# -*- coding:utf-8 -*-
import re,urllib,sys,os,time def getAllUrl():
entry=sys.argv[1]
#try:
getPage=urllib.urlopen(entry).read()
#except:
# print "Error" pattern=re.compile(r'<a href="(.+? )".+?>')
web_site_pattern=re.compile(r'(http:.+?)')
all_url = pattern.findall(getPage)
for url in all_url:
if web_site_pattern.match(url):
print url
#print url print "done" def download_pic():
url=sys.argv[1];
#local_path="C:/Tools/source/"
connection=urllib.urlopen(url)
data=connection.read()
print "Waiting to get data"
time.sleep(3)
connection.close() #analyze
#p=re.compile(r'img width="\d+".+src="(.+)".+')
download_pic_pattern=re.compile(r'<img src="(.+?\.jpg)".+?/>')
#p10=re.compile(r'(.+)\.jpg')
all_url=download_pic_pattern.findall(data)
#print all_url
i=1
directory="C:/Tools/source"
name_pattern=re.compile(r'/(\w+?\.jpg)')
if not os.path.exists(directory):
os.mkdir(directory) for urls in all_url:
print urls
#print "working" #print local_path
i=i+1
name=name_pattern.findall(urls)
print name[0]
local_path="C:/Tools/source/%s" % name[0]
jpeg_connection=urllib.urlopen(urls) jpeg=jpeg_connection.read()
time.sleep(1)
print "waiting"
f=file(local_path,"wb")
f.write(jpeg) f.close()
jpeg_connection.close()
#i=i+1 #f=file(local_path,"wb")
#f.write(data)
#f.close()
print("Done") def download_pic_2():
url=sys.argv[1];
local_path="C:/Tools/a.jpg"
data=urllib.urlretrieve(url,local_path)
print("Done") def regulation():
str1="abc123*GBK1024abc*defb1kc12*addd" p1=re.compile(r'abc')
print p1.findall(str1) p2=re.compile(r'a.c')
print p2.findall(str1) p3=re.compile(r'abc\*')
print p3.findall(str1) p4=re.compile(r'[abc]12')
print p4.findall(str1) p5=re.compile(r'\d\*')
print p5.findall(str1) p6=re.compile(r'a[^\d]')
print p6.findall(str1) p7=re.compile(r'a[^\d]*')
print p7.findall(str1) p8=re.compile(r'[a-zA-Z]+(\d+)')
print p8.findall(str1) str2="dadfae ef <img atl=\"500\" src=\"www.qq.com/1.jpg\" width=\"700\"> asdfe aa<ima" p9=re.compile(r'<img .+ src="(.+)" .+>')
urls=p9.findall(str2)
#print
print urls
for url in urls:
print url if __name__ =="__main__":
#main()
#download_pic_2()
#regulation()
download_pic()
#getAllUrl()

#######兴许

后面改动了代码,使用beautifulsoup,能够更大范围的下载图片

代码例如以下: http://www.30daydo.com/article/56

python批量下载色影无忌和蜂鸟的图片 爬虫小应用的更多相关文章

  1. 用python批量下载图片

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

  2. 用Python批量下载DACC的MODIS数据

    本人初次尝试用Python批量下载DACC的MODIS数据,记下步骤,提醒自己,数据还在下载,成功是否未知,等待结果中...... 若有大佬发现步骤有不对之处,望指出,不胜感激. 1.下载Python ...

  3. 用python批量下载贴吧图片 附源代码

    环境:windows 7 64位:python2.7:IDE pycharm2016.1 功能: 批量下载百度贴吧某吧某页的所有帖子中的所有图片 使用方法: 1.安装python2.7,安装re模块, ...

  4. python——批量下载图片

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

  5. python批量下载微信好友头像,微信头像批量下载

    #!/usr/bin/python #coding=utf8 # 自行下载微信模块 itchat 小和QQ496631085 import itchat,os itchat.auto_login() ...

  6. Python 批量下载BiliBili视频 打包成软件

    文章目录 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手.很多已经做案例的人,却不知道如何去学习更加高深的知识.那么针对这三类人,我给大家 ...

  7. Python - 批量下载 IIS 共享的文件

    1.说明 用 IIS 以WEB形式发布了本地文件夹,提供文件下载,并设置了访问权限:默认下载需要点击一个一个的下载,web界面如下: 3.脚本 执行脚本批量下载文件,会在当前目录创建文件夹,并压缩该文 ...

  8. 047_批量下载有序文件(pdf、图片、视频等等)

    #!/bin/bash#本脚本准备有序的网络资料进行批量下载操作(如 01.jpg,02.jpg,03.jpg)#设置资源来源的域名连接 url="http://www.test.com/& ...

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

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

随机推荐

  1. STM32 软件模拟 IIC 代码,标准库、HAL库可用

    #ifndef _IIC_H #define _IIC_H #include "stdio.h" #include "stm32f1xx_hal.h" /* 定 ...

  2. vue实现双向绑定原理

  3. HDU 2686 Matrix(最大费用最大流+拆点)

    题目链接:pid=2686">http://acm.hdu.edu.cn/showproblem.php?pid=2686 和POJ3422一样 删掉K把汇点与源点的容量改为2(由于有 ...

  4. java.lang.ClassNotFoundException: org.jaxen.JaxenException

    java.lang.ClassNotFoundException: org.jaxen.JaxenException java.lang.ClassNotFoundException: org.jax ...

  5. sqlplus登录提示:ORA-12162:TNS:net service name is incorrectly specified错误

    [root@localhost ~]# su - oracle [oracle@localhost ~]$ sqlplus '/as sysdba' SQL*Plus: Release 11.2.0. ...

  6. DICOM医学图像处理:fo-dicom网络传输之 C-Echo and C-Store

    背景: 上一篇博文对DICOM中的网络传输进行了介绍.主要參照DCMTK Wiki中的英文原文.通过对照DCMTK与fo-dicom两个开源库对DICOM标准的详细实现,对理解DICOM标准有一个更直 ...

  7. myeclipse配置内存

    1.javaee项目假设耗费的内存过大,须要配置内存大小: 下图是配置tomcat结果:Optional program arguments: -Xms512M -Xmx512M -XX:PermSi ...

  8. Cocos2d-x 常见宏

    1)NS_CC_BEGIN cocos2d命名空间開始 2) NS_CC_END  cocos2d命名空间结束 3)USING_NS_CC 声明cocos2d命名空间 4)CC_SYNTHESIZE_ ...

  9. Checkmarx VisualStudio plugin installation process.

    1-      Configuration of plugin VSTudio Prerequisite: -Your visual studio MUST be up to date with th ...

  10. 新手村,学会做人选数 https://www.luogu.org/problemnew/show/P1036

    #include<cstdio> #include<cmath> #include<string.h> using namespace std; int n,k,s ...