mxpro筛选.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # File : mxpro筛选.py
  4. # Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
  5. # Date : 2022/9/13
  6. import re
  7. import requests
  8. from utils.htmlParser import jsoup
  9. headers = {'user-agent':'Mozilla/5.0 (Linux; Android 11; M2007J3SC Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045714 Mobile Safari/537.36'}
  10. def getFilters(url):
  11. cate_id = str(re.search('.*/(\d+)', url).groups()[0])
  12. print(cate_id)
  13. jsp = jsoup(url)
  14. pdfh = jsp.pdfh
  15. pdfa = jsp.pdfa
  16. print(jsp)
  17. r = requests.get(url,headers=headers)
  18. r.encoding = r.apparent_encoding
  19. html = r.text
  20. cls_list = pdfa(html,'.module-class&&.module-class-items')
  21. print(len(cls_list))
  22. ft_dict = {cate_id:[]}
  23. for cls in cls_list:
  24. tt = pdfh(cls,'.module-item-title&&Text')
  25. values = pdfa(cls,'.module-item-box&&a')
  26. # vl = [{"n":pdfh(i,'a&&Text'),"v":pdfh(i,'a&&href')} for i in values]
  27. vl = [{"n":pdfh(i,'a&&Text'),"v":re.search('(.*?)-(.*)',pdfh(i,'a&&href'),re.M|re.I|re.S).groups()[1].replace('.html','').replace('-','')} for i in values]
  28. ft_dict[cate_id].append({
  29. 'key': tt,
  30. 'name': tt,
  31. 'value': vl
  32. })
  33. print(ft_dict)
  34. return ft_dict
  35. if __name__ == '__main__':
  36. new_dict = {}
  37. for i in '20&1&2&3&4&23'.split('&'):
  38. ft_dict = getFilters(f'https://lanmeiguojiang.com/show/{i}-----------.html')
  39. new_dict.update(ft_dict)
  40. print(new_dict)