爱奇艺视频解析
一个简单的爬取爱奇艺视频连接的代码解析接口使用的时BL接口,视频名字暂定"二十不惑"(懒得改了)
# -*- coding: utf-8 -*-
import requests
import re
import json
# import sys
# if len(sys.argv) == 1:
# print("请输入关键字进行搜索")
# exit(0)
# keyword = sys.argv
keyword = '二十不惑'
url = 'https://so.iqiyi.com/so/q_' + keyword
parse_url = 'https://vip.bljiex.com/?v='
# UA使用手机端
headers = {
'user-agent':
'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Mobile Safari/537.36 Edg/84.0.522.52'
}
session = requests.session()
r = session.get(url, headers=headers)
data = re.findall('window.__INITIAL_STATE__=(.*?);\(function', r.text)
dict_data = json.loads(data)
# print(dict_data)
result = dict_data.get('search').get('searchResult').get('docs')
for each in result:
title = each.get('albumTitle')
print(title)
info = each.get('videoinfos')
for i in info:
item = {
'itemTitle': i.get('itemTitle'),
'itemLink': parse_url + i.get('itemLink'),
}
print(item)
print('\n')
{:10_254:}怎么用
页:
[1]