加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
selum.py 2.81 KB
一键复制 编辑 原始数据 按行查看 历史
GuLu 提交于 2022-09-18 17:33 . selenium
import re
import time
from selenium import webdriver
from selenium.webdriver import ActionChains
from tqdm import tqdm
import checkOutTime
import sendMesToWechat
def selCraw(name, title, url, start_time, access_token):
browser = webdriver.Chrome()
browser.get(url)
time.sleep(3)
action = ActionChains(browser)
try:
e = browser.find_element('xpath', '//*[@id="lelevideo"]')
except:
contxt = ' '
data = sendMesToWechat.getFuiJson(contxt)
sendMesToWechat.send_message(access_token, data)
action.move_to_element(e).perform()
action.context_click(e).perform()
e = browser.find_element('xpath', '//*[@id="player"]/div[9]/div[1]/a')
action.click(e).perform()
text = browser.page_source
# print(text)
kind_data = re.findall('视频类型</span>(.*?)/span>', text, re.S)[0]
kind = re.findall('<span class="leleplayer-info-panel-item-data">(.*?)<', kind_data)[0]
# print('kind:'+kind)
url_data = re.findall('视频地址</span>(.*?)/span>', text, re.S)[0]
url_video = re.findall('<span class="leleplayer-info-panel-item-data">(.*?)<', url_data)[0]
# print(url_video)
browser.quit()
if kind == 'normal':
video_content = checkOutTime.getData(url_video, name, title, access_token).content
time.sleep(1)
with open('C:\\Users\\咕噜咕噜哟\\Desktop\\视频动漫\\' + name + '\\' + title + '.mp4', mode="wb") as video:
video.write(video_content)
end_time = time.time()
time_c = end_time - start_time
# 发送消息提醒
# contxt = name + ' ' + title
# data = sendMesToWechat.getSucJson(contxt)
# sendMesToWechat.send_message(access_token, data)
print('视频下载完成!!! 下载所用时间:' + str(time_c))
else:
m3u8_data = checkOutTime.getData(url_video, name, title, access_token).text
time.sleep(1)
# sub替换 提取需要的
m3u8_data = re.sub('#EXT.*', ' ', m3u8_data).split()
for ts in tqdm(m3u8_data):
# print(ts)
ts_url = checkOutTime.getFinalUrl(url_video) + ts
# print(ts_url)
ts_content = checkOutTime.getData(ts_url, name, title, access_token).content
# print("请求数据成功")
with open('C:\\Users\\咕噜咕噜哟\\Desktop\\视频动漫\\' + name + '\\' + title + '.mp4', mode="ab") as video:
# print("传入中。。。")
video.write(ts_content)
end_time = time.time()
time_c = end_time - start_time
# 发送消息提醒
# contxt = name + ' ' + title
# data = sendMesToWechat.getSucJson(contxt)
# sendMesToWechat.send_message(access_token, data)
print('视频下载完成!!! 下载所用时间:' + str(time_c))
time.sleep(2)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化