爱奇艺筛选.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # File : 爱奇艺筛选.py
  4. # Author: DaShenHan&道长-----先苦后甜,任凭晚风拂柳颜------
  5. # Date : 2022/9/12
  6. import json
  7. import requests
  8. from pprint import pprint
  9. cates = '1&2&3&4&6&5&16'.split('&')
  10. urls = [f'https://pcw-api.iqiyi.com/search/category/categoryinfo?brand=IQIYI&channel_id={cate}&include_knowledge_content_type=&locale=zh' for cate in cates]
  11. print(urls)
  12. 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'}
  13. data = [{
  14. "id": "mode",
  15. "name": "综合排序",
  16. "child": [{
  17. "name": "热播榜",
  18. "id": 11
  19. }, {
  20. "name": "好评榜",
  21. "id": 8
  22. }, {
  23. "name": "新上线",
  24. "id": 4
  25. }]
  26. },
  27. {
  28. "id": "year",
  29. "name": "全部年份",
  30. "child": [{
  31. "name": "2022",
  32. "id": 2022
  33. }, {
  34. "name": "2021",
  35. "id": 2021
  36. }, {
  37. "name": "2020",
  38. "id": 2020
  39. }, {
  40. "name": "2019",
  41. "id": 2019
  42. }, {
  43. "name": "2018",
  44. "id": 2018
  45. }, {
  46. "name": "2017",
  47. "id": 2017
  48. }, {
  49. "name": "2016-2011",
  50. "id": "2011_2016"
  51. }, {
  52. "name": "2010-2000",
  53. "id": "2000_2010"
  54. }, {
  55. "name": "90年代",
  56. "id": "1990_1999"
  57. }, {
  58. "name": "80年代",
  59. "id": "1980_1989"
  60. }, {
  61. "name": "更早",
  62. "id": "1964_1979"
  63. }]
  64. },
  65. {
  66. "id": "is_purchase",
  67. "name": "全部资费",
  68. "child": [{
  69. "name": "免费",
  70. "id": 0
  71. }, {
  72. "name": "会员",
  73. "id": 1
  74. }, {
  75. "name": "付费",
  76. "id": 2
  77. }]
  78. }
  79. ]
  80. ft_dict = {}
  81. def getOne(url,cate):
  82. r = requests.get(url, headers=headers)
  83. html = r.json()
  84. filters = html['data']
  85. new_list = list(tuple(data))
  86. new_list.extend(filters)
  87. # cate_id = html['code']
  88. cate_id = cate
  89. ft_dict[cate_id] = []
  90. for i in range(len(new_list)):
  91. ft = new_list[i]
  92. if ft['name'] == '地区':
  93. ft['id'] = 'three_category_id'
  94. # elif ft['name'] == '类型':
  95. # ft['id'] = 'type'
  96. # elif ft['name'] == '规格':
  97. # ft['id'] = 'spec'
  98. value = [{"n":"全部","v":""}]
  99. vl = [{"n":i['name'],"v":i['id']} for i in ft['child']]
  100. value.extend(vl)
  101. ft_dict[cate_id].append({
  102. 'key':str(ft['id']),
  103. 'name':ft['name'],
  104. 'value':value
  105. })
  106. return ft_dict
  107. # print(ft_dict)
  108. for i in range(len(urls)):
  109. url = urls[i]
  110. cate = cates[i]
  111. # print(getOne(urls[0]))
  112. # print(getOne(url))
  113. getOne(url,cate)
  114. print(ft_dict)
  115. with open('爱奇艺筛选.json',mode='w+',encoding='utf-8') as f:
  116. f.write(json.dumps(ft_dict,ensure_ascii=False,indent=4))