Ai
1 Star 0 Fork 2

Lindddt/基于Python的爬取TwitCasting视频的工具

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
dealHtml.py 1.00 KB
一键复制 编辑 原始数据 按行查看 历史
PtvMiKu 提交于 2020-02-27 13:56 +08:00 . first upload
import requests
import io
import os
import urllib.request
from lxml import etree
url = ''
def filename_html(url):
url_before = url
url_after = url_before.split("/")
return url_after[3] + "_" + url_after[5] + ".html"
def filename_m3u8(url):
url_before = url
url_after = url_before.split("/")
return url_after[3] + "_" + url_after[5] + ".m3u8"
def filename_txt(url):
url_before = url
url_after = url_before.split("/")
return url_after[3] + "_" + url_after[5] + ".txt"
def download_html(url):
response = urllib.request.urlopen(url)
string = response.read()
html = string.decode('utf-8')
if not os.path.exists('temp/'):
os.mkdir('temp/')
f = open('temp/' + filename_html(url),'w',encoding='utf-8')
f.write(html)
f.close()
def m3u8_url(url):
html = etree.parse('temp/' + filename_html(url),etree.HTMLParser())
video_tag = html.xpath('//video/@data-movie-playlist')
video_tag_aftercut = video_tag[0].split("\"")
return video_tag_aftercut[9]
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/Lindddt/PythonTwitCastingWebCrawler.git
git@gitee.com:Lindddt/PythonTwitCastingWebCrawler.git
Lindddt
PythonTwitCastingWebCrawler
基于Python的爬取TwitCasting视频的工具
master

搜索帮助