提交 4827fa41 编写于 作者: Q qq_44252895

Wed Nov 8 10:40:00 CST 2023 inscode

上级 c8222ff6
run = "pip install -r requirements.txt;python main.py"
language = "python"
[packager]
AUTO_PIP = true
......@@ -9,4 +10,7 @@ PATH = "${VIRTUAL_ENV}/bin:${PATH}"
PYTHONPATH = "$PYTHONHOME/lib/python3.10:${VIRTUAL_ENV}/lib/python3.10/site-packages"
REPLIT_POETRY_PYPI_REPOSITORY = "http://mirrors.csdn.net.cn/repository/csdn-pypi-mirrors/simple"
MPLBACKEND = "TkAgg"
POETRY_CACHE_DIR = "/root/${PROJECT_DIR}/.cache/pypoetry"
\ No newline at end of file
POETRY_CACHE_DIR = "/root/${PROJECT_DIR}/.cache/pypoetry"
[debugger]
program = "main.py"
import requests
from bs4 import BeautifulSoup
import re
import os
import base64
import re
# 设置请求头,模拟浏览器访问
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
# 获取电影天堂最新电影页面的源代码
url = 'https://www.dytt8.net/html/gndy/dyzz/list_23_1.html'
response = requests.get(url, headers=headers)
response.encoding = 'gb2312' # 设置编码格式
html = response.text
# 使用BeautifulSoup解析网页源代码
soup = BeautifulSoup(html, 'html.parser')
# 创建全局的 Session 对象
session = requests.Session()
session.headers.update(headers)
# 获取电影列表
movie_list = soup.find_all('a', {'class': 'ulink'})
# 遍历电影列表,获取电影名、下载链接、评分等信息
for movie in movie_list:
movie_name = movie.text # 电影名
movie_url = movie['href'] # 下载链接
# 判断电影是否已经下载过
if not os.path.exists(movie_name):
def download_movie(movie_name, movie_url, download_path):
"""
下载电影函数
"""
movie_name = re.sub(r'[\\/:*?"<>|\r\n]+', '', movie_name) # 替换文件名中的特殊字符
file_path = os.path.join(download_path, movie_name + '.torrent')
if not os.path.exists(file_path):
# 调用迅雷进行下载
thunder_url = 'thunder://' + base64.b64encode(('AA' + movie_url + 'ZZ').encode('utf-8')).decode('utf-8')
os.system('start ' + thunder_url)
with open(file_path, 'wb') as f:
f.write(requests.get(thunder_url).content)
print(f"{movie_name} 下载完成!")
else:
print(f"{movie_name} 已经下载过了!")
def get_movie_list(session,url):
"""
获取电影列表函数
"""
response = session.get(url)
response.encoding = 'gb2312' # 设置编码格式
html = response.text
soup = BeautifulSoup(html, 'html.parser')
movie_list = soup.find_all('a', {'class': 'ulink'})
return movie_list
if __name__ == '__main__':
# 创建电影下载目录
download_path = os.path.join(os.getcwd(), '电影下载')
if not os.path.exists(download_path):
os.makedirs(download_path)
# 获取电影天堂最新电影页面的源代码
url = 'https://www.dytt8.net/html/gndy/dyzz/list_23_1.html'
movie_list = get_movie_list(url)
# 遍历电影列表,获取电影名、下载链接等信息
for movie in movie_list:
movie_name = movie.text # 电影名
movie_url = movie['href'] # 下载链接
# 判断电影是否已经下载过
if not os.path.exists(os.path.join(download_path, f"{movie_name}.torrent")):
download_movie(movie_name, movie_url, download_path)
# 打印电影信息
print(movie_name, movie_url)
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册