代码拉取完成,页面将自动刷新
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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。