Python 使用urlretrieve 时候 出现错误%22 http错误出现错误

写的程序是实现网上爬图片,程序要求地址

http://tieba.baidu.com/p/2166231880

错误提示:

IOError: [Errno url error] unknown url type: '%22http'


参考的网上信息是

http://blog.youkuaiyun.com/shy871265996/article/details/1301623   3

修改的方式:

b = urllib.urlretrieve(urlindex.strip('"'), '%s.jpg' % (n))#.strip('"')

附上自己的代码:

import os,urllib,re,time
#写一个爬虫
path = 'C:\Users\scc\Desktop\python\pythonPa\\t'#后面再加一个位置就不对?
os.chdir(path)
url ='http://tieba.baidu.com/p/2166231880'
def get_html():
    with open('b.txt','w+') as f:
        htm = urllib.urlopen(url).read()
        f.write(htm)
        f.close()
    return htm

def patt_findall():
    ap = []
    htm = get_html()
    patt = r'<img pic_type="0" class="BDE_Image" src=(.*?) bdwater="杉本有美吧'#'<div class="wrap2">(.*?)</div>'
    content_all = re.findall(patt,htm)
    for i in content_all:
        if  "pic_ext" in i :
            continue
        ap.append(i)
    return ap
#下载文件
def DownLoad_img():
    n = 1
    ap = patt_findall()
    for urlindex in ap:
        print 11,urlindex
        time.sleep(3)
        #print 222,urllib.quote(urlindex)
        b = urllib.urlretrieve(urlindex.strip('"'), '%s.jpg' % (n))#.strip('"')
        #urllib.urlretrieve(urlindex,'1.jpg')#%(n))
        n+=1

if __name__ =='__main__':
    a = DownLoad_img()


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值