首页 > 编程语言 > 详细

python爬图 准备多线程

时间:2019-05-06 20:31:33      阅读:336      评论:0      收藏:0      [点我收藏+]
#codeing = utf-8
#官方3.0版本已经把urllib2,urlparse等五个模块都并入了urllib中
import urllib.request
import re

def getHtml(url):
    #打开连接
    page = urllib.request.urlopen(url)
    #获取网页内容
    html = page.read()
    print(html)
    return html

def getImg(html):
    #正则表达式
    reg = rsrc="(.+?\.jpg)" alt=
    imgre = re.compile(reg)
    #以列表的形式返回能匹配的子串
    imgList = re.findall(imgre,html.decode(utf-8))
    x=0
    for imgurl in imgList:
        #把爬取到的资源保存到本地
        urllib.request.urlretrieve(imgurl,%s.jpg % x)
        x+=1
    return imgList
#输入你想要爬取的网站
#url=‘https://www.113yq.com/pic/html28/index_3.html‘
html=getHtml(new_url)
#html=getHtml("http://pic.yxdown.com/list/0_0_1.html")
print(getImg(html))

--------------------- 
作者:热心市民大G 
来源:CSDN 
原文:https://blog.csdn.net/tyt_xiaotao/article/details/80209398 
版权声明:本文为博主原创文章,转载请附上博文链接!

 

python爬图 准备多线程

原文:https://www.cnblogs.com/xiaohe520/p/10821679.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!