|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这是之前写的代码,以前正常,现在反馈给我不想要的东西- import requests
- import random
- import re
- import os
- import urllib.request as u
- def get_html(url):
- user = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0"
- ips = [
- '222.161.56.166',
- '122.238.12.191',
- '61.191.41.130'
- ]
- ip = random.choice(ips)
- p = u.ProxyHandler({'http':ip})
- opener = u.build_opener(p)
- u.install_opener(opener)
- rep = requests.get(url,headers={'User-Agent':user})
- return rep
- name = input('请输入要查找的商品:')
- num = int(input('请输入页数:'))
- key = u.quote(name)
- os.mkdir(name)
- os.chdir(name)
-
- def main():
- for j in range(num):
- url = 'https://s.taobao.com/search?q=' + key + '&s='+ str(j*44)
- html = get_html(url).text
- s = re.findall(r'"pic_url":"([^"]+?)".+?"view_price":"([^"]+?)".+?"view_sales":"([^"]+?)"',html)
-
- os.mkdir('%s%d'%(name,j+1))
- os.chdir('%s%d'%(name,j+1))
-
- for i in s:
- img = get_html(url=('http:' + i[0]))
-
- with open('%s元_%s.jpg'%(i[1],i[2]),'wb') as f:
- f.write(img.content)
-
- os.chdir(os.pardir)
-
- if __name__ == '__main__':
- main()
-
-
复制代码
|
-
|