1 回答
TA贡献1836条经验 获得超4个赞
所以,显然有808集。看看这个代码,这里有很多事情发生,但它很容易理解。我测试了大约5-6集的下载,它的工作原理...
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from http.client import RemoteDisconnected
import time
def get_browser():
chrome_options = Options()
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument('--disable-notifications')
chrome_options.add_argument('--incognito')
driver = webdriver.Chrome(options=chrome_options)
return driver
driver = get_browser()
page_url = "https://www.kiss-anime.ws/Anime-detective-conan-1"
try:
driver.set_page_load_timeout(40)
driver.get(page_url)
except TimeoutException:
raise Exception(f"\t{page_url} - Timed out receiving message from renderer")
except RemoteDisconnected:
raise Exception(f"\tError 404: {page_url} not found.")
WebDriverWait(driver, timeout=40).until(EC.presence_of_element_located((By.ID, "selectEpisode")))
driver.find_element_by_id("selectEpisode").click()
soup = BeautifulSoup(driver.page_source, "html.parser")
options = soup.find("select", attrs={"id": "selectEpisode"}).find_all("option")
print(f"Found {len(options)} episodes...")
base_url = "https://www.kiss-anime.ws/"
for idx, option in enumerate(options):
print(f"Downloading {idx+1} of {len(options)}...")
page_url = option['value']
try:
driver.set_page_load_timeout(40)
driver.get(page_url)
except TimeoutException:
print(f"\t{page_url} - Timed out receiving message from renderer")
continue
except RemoteDisconnected:
print(f"\tError 404: {page_url} not found.")
continue
WebDriverWait(driver, timeout=40).until(EC.presence_of_element_located((By.ID, "divDownload")))
driver.find_element_by_id("divDownload").click()
print(f"\t Downloading...")
time.sleep(15)
driver.quit()
print("done")
因此,首先,我在chrome浏览器中打开URL,并读取总共808的下拉列表值。现在,我正在浏览这808个URL中的每一个,以获取下载视频所需的实际链接。通过使用循环,我实际上是在模拟按钮点击,视频开始下载。请记住更改位置,该位置应表示根据您的互联网速度下载一集所需的大约时间(秒)。.click()time.sleep(x)x
您需要使用 安装和打包。另外,下载chromedriver.exe并确保它与此脚本的路径相同。
添加回答
举报