|
|
1鱼币
为什么已经导入python中的urllib.request函数库,但是在运行时候显示AttributeError: module 'urllib' has no attribute 'reuqest'网上说可以删除pyc以后尝试,但是依然不行,请问一下为
- import urllib.request
- import random
- 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.reuqest.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)
- html = response.read()
- he=html.deconde('utf-8')
- return html
- def download():
- add={}
- 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)
- if b!= -1:
- b=a+9
- else:
- add.append((a+9,b+4))
- a=find('img_src=',b)
- for each in add:
- filename=each.split('/')[-1]
- with open(filname,'wb') as f:
- img=urlopen(each)
- f.write(img)
- if __name__=='__main__':
- header={'User_Ager',}
- download();
复制代码 什么
|
|