python视频解析库_视频解析(python/php)

PHP

$url = '视频分享链接';

$data = httpGet($url);

$data = strstr($data, 'playAddr');

$data = strstr($data, '&line', 1);

$data = strstr($data, 'https');

$url = str_replace('playwm', 'play', $data);

$arr = get_headers($url, 1);

echo $arr['Location'];

function httpGet($url)

{

$user_agent = 'Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0';

$ch = curl_init();

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);

curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);

curl_setopt($ch, CURLOPT_URL, $url);

$output = curl_exec($ch);

curl_close($ch);

return $output;

}

Python

import requests

url = 'https://www.iesdouyin.com/share/video/6561348471406726407'

headers = {'user-agent': 'Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0'}

r = requests.get(url, headers=headers)

strs = r.text

start = strs.find('playAddr')

end = strs.find('&line')

res = strs[start:end]

res = res.replace('playAddr: "','')

url = res.replace('playwm','play')

r = requests.get(url, headers=headers)

print(r.url)

你可能感兴趣的:(python视频解析库)