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

    xiaoxiao2021-03-25  326

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

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

    错误提示:

    IOError: [Errno url error] unknown url type: '"http'

    参考的网上信息是

    http://blog.csdn.net/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()

    转载请注明原文地址: https://ju.6miu.com/read-3376.html

    最新回复(0)