|
|
3鱼币
- import urllib.request
- import random
- import os
- def open(url):
- proxies=['221.226.36.174','36.45.179.150','101.132.121.157']
- proxie=random.choice(proxies)
- proxy_supptor = urllib.request.ProxyHandler({'http':proxie})
- opener=urllib.request.build_opener(proxy_supptor)
- urllib.request.install_opener(opener)
- head={'User_Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}
- response=urllib.request.Request(url, headers=head)
- temp=urllib.request.urlopen(response)
- html = temp.read()
- he=html.deconde('utf-8')
- return he
- def download():
- os.mkdir('OOXX')
- os.chdir('OOXX')
- list=[]
- url='http://googleads.g.doubleclick.net/pagead/gen_204?id=wfocus&gqid=KeKkWr7jJcHw9QWFvIko&qqid=CICS39_m49kCFQgRvQod6RIG5w&fg=1'
- html=open(url)
- a=html.find('img_src=')
- while a != -1:
- b=html.find('.jpg',a,a+255)
- if b!= -1:
- b=a+9
- else:
- list.append(html[a+9:b+4])
- a=html.find('img_src=',b)
- for each in list:
- filename = each.split('/')[-1]
- with open(filename, 'wb') as f:
- img = url_open(each)
- f.write(img)
- if __name__=='__main__':
- header={'User_Ager',}
- download()
复制代码
不知道为什么会报错,我找了好久没找到,有大佬能提供下解决方法吗
head={'User_Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}
红色逗号改成:,不然不是字典而是集合
|
最佳答案
查看完整内容
head={'User_Agent','Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36'}
红色逗号改成:,不然不是字典而是集合
|