python爬虫解析m3u8文件,file not found?
1.解析m3u8文件时,想要提取其中的ts地址,但是无法解析,总是报错:file not found。
2.代码如下:
url = 'https://bobolj.com/20210324/M...'
headers = {
"Referer":"http://www.foxjoy.net/vodtype/20-2.html", "Upgrade-Insecure-Requests":"1",
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36",
}
ts = requests.get(url,headers=headers).text
print(ts)
3.原网站信息请求头如下:
实在是不知道哪里出问题了?我完全构造请求头也不行,还是报错,请求各位帮忙解答一下,谢谢
回答:
我没有构造headers,直接get就成了
In [1]: url="https://bobolj.com/20210324/MbbQwG6M/500kb/hls/index.m3u8"In [2]: import requests
In [3]: r=requests.get(url)
In [4]: r.status_code
Out[4]: 200
In [6]: from lxml import etree
In [7]: d=etree.HTML(r.text)
In [8]: etree.dump(d)
<html>
<body>
<p>#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:15
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:15,
/20210324/MbbQwG6M/500kb/hls/0bCfxaR5.ts
...
#EXTINF:2.76,
/20210324/MbbQwG6M/500kb/hls/DzmSJA7L.ts
#EXT-X-ENDLIST
</p>
</body>
</html>
以上是 python爬虫解析m3u8文件,file not found? 的全部内容, 来源链接: utcz.com/a/163912.html