谢谢各位,我早上想到了好的方法了,代码分享如下:
[Asm] 纯文本查看 复制代码 from lxml import etree
import requests
UA伪装 = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36'}
def bianhao(keyword):
url=f'http://www.rrys2020.com/search?keyword={keyword}'
response = requests.get(url=url,headers=UA伪装).text
tree = etree.HTML(response)
name = tree.xpath('//strong[@class="list_title"]//text()')
a=tree.xpath('//div[@class="t f14"]//@href')
编号=[i.split("/")[2] for i in a]
# 类别=[i.split("/")[1] for i in a]
输出=dict(zip(name,编号))
return 输出
def daima(编号):
url=f'http://www.rrys2020.com/resource/index_json/rid/{编号}/channel/movie'
response = requests.get(url=url,headers=UA伪装).text
response = response.replace('var index_info=','')
# 响应数据 = 响应数据.replace(');','')
# json = json.loads(response)
tree = etree.HTML(response)
daima = tree.xpath('//a/@href')[0]
daima=daima.split("=")[1].replace('\\"', '')
return daima
def url_get(daima):
url=f'http://got002.com/api/v1/static/resource/detail?code={daima}'
response = requests.get(url=url, headers=UA伪装).json().get('data').get('list')
season =response
season_count=len(season)
for i in range(0,season_count):
第几季=season[i]['season_cn']
print(第几季)
集=season[i].get('items').get('MP4')
#可把'MP4'替换为APP、HDTV、WEB-720P、WEB-1080P
集_count=len(集)
# for n in range(0,集_count):
name=[集[n].get('name') for n in range(0,集_count)]
# data.list[0].items.MP4[0].name
address=[集[n].get('files')[1].get('address') for n in range(0,集_count)]
# data.list[0].items.MP4[0].files[0].address
print(name)
print('-' * 120)
print(address)
print('*'*120)
if __name__ == '__main__':
a=bianhao('无垠的太空')
序号=1
for i in a:
print(f'{序号}、{i}')
序号+=1
num=int(input('请输入要搜索的序号'))
b=list(a.values())[num-1]
c=daima(b)
url_get(c)
|