91批量 python源代码,正常跑没问题,其他功能你们自由发挥

  • A+
所属分类:软件应用教程

代码是有代码基础的人的,
没有代码基础的,可以用百度网盘里的程序去跑,
https://pan.baidu.com/s/1huEU-EVjzn-daNBfbIkX6w 密码:hjco

  1. # coding=gbk
  2. from multiprocessing import Pool
  3. import time
  4. import re
  5. import multiprocessing
  6. from bs4 import BeautifulSoup
  7. import  requests
  8. from xlrd import open_workbook
  9. from xlutils.copy import copy
  10. print(\"程序开始执行 by cl monkey13180\")
  11. try:
  12.     f = open('config.txt', 'r')
  13.     config = str(f.read()).split('\n')
  14.     start = config[0]
  15.     end = config[1]
  16.     url = config[2]
  17. except Exception as e:
  18.     print(\"请在当前目录下创建config.txt, 请按顺序填写页码,fid,域名并敲回车!\")
  19. class Pool_91(object):
  20.     def __init__(self,range,res):
  21.         self.range=range
  22.         self.res=res
  23.     def run(self):
  24.         # print(self.res)
  25.         AllData = []
  26.         for x in range(self.range[0], self.range[1]):
  27.             proxy_list = []
  28.             true_url = self.getTrueUrl(x)
  29.             proxy_list.append(true_url)
  30.             proxy_list.append(self.res[x][1])
  31.             AllData.append(proxy_list)
  32.         # print(AllData)
  33.         return AllData
  34.     def getTrueUrl(self,num):
  35.         print('正在保存:{}{}'.format(self.res[num][1],self.res[num][0]))
  36.         try:
  37.             data = {
  38.                 'url': self.res[num][0]
  39.             }
  40.             aaa = requests.post('http://cj.9530.net/index.php', data=data, allow_redirects=False)
  41.             soup = BeautifulSoup(aaa.content, 'lxml')
  42.             aa = (soup.find_all(attrs={'download': 'a'}))
  43.             true_url =(aa[0].get('href'))
  44.         except:
  45.             pass
  46.         return true_url
  47.     def mycallback(self,x):
  48.         rexcel = open_workbook(\"list.xls\")
  49.         rows = rexcel.sheets()[0].nrows
  50.         excel = copy(rexcel)
  51.         table = excel.get_sheet(0)
  52.         #
  53.         row = rows
  54.         for value in x:
  55.             table.write(row, 0, time.strftime(\"%Y-%m-%d %H:%M:%S\"))
  56.             table.write(row, 1, value[1])
  57.             table.write(row, 2, value[0])
  58.             row += 1
  59.         excel.save(\"list.xls\")
  60. if __name__ == '__main__':
  61.     multiprocessing.freeze_support()
  62.     AllUrl = []
  63.     for i in range(int(start), int(end)+1):  # 1-6
  64.         time.sleep(2)
  65.         data={
  66.             'session_language':'cn_CN'
  67.         }
  68.         page = requests.post('{}&page={}'.format(url,i),data)
  69.         soup = BeautifulSoup(page.content, 'html.parser')
  70.         TempUrlList = soup.find_all(href=re.compile('view_video'),title='')
  71.         TempUrlList1 = soup.find_all(class_='listchannel')
  72.         for i in TempUrlList:
  73.             UrlList = []
  74.             UrlList.append(i['href'])
  75.             UrlList.append(i.findAll('img')[0]['title'])
  76.             AllUrl.append((UrlList))
  77.     all_num = len(AllUrl)
  78.     num = 4  # number of cpu cores
  79.     per_num, left = divmod(all_num, num)
  80.     s = range(0, all_num, per_num)
  81.     res = []
  82.     for i in range(len(s) - 1):
  83.         res.append((s[i], s[i + 1]))
  84.     res.append((s[len(s) - 1], all_num))
  85.     pool = Pool()
  86.     for i in res:
  87.         _91pron = Pool_91(i,AllUrl)
  88.         pool.apply_async(_91pron.run, (), callback=_91pron.mycallback)
  89.     pool.close()
  90.     pool.join()

环境python3.6
写的不好请见谅,早上更新了下程序,怕大家看不到,就新开了个帖子.