sehuatang pdf 优化

This commit is contained in:
liuwei
2025-12-25 15:36:02 +08:00
parent 408bf12342
commit f5a51fa2ec
3 changed files with 42 additions and 25 deletions

View File

@@ -3,6 +3,7 @@ import os
import requests
from io import BytesIO
import undetected_chromedriver as uc
if os.name == 'nt':
try:
uc.Chrome.__del__ = lambda self: None
@@ -172,8 +173,22 @@ def fetch_and_create_pdf(url):
def pdf_file_path_undetected():
url = 'https://www.sehuatang.net/forum.php?mod=forumdisplay&fid=103&filter=typeid&typeid=481'
return fetch_and_create_pdf(url)
try:
url = 'https://www.sehuatang.net/forum.php?mod=forumdisplay&fid=103&filter=typeid&typeid=481'
pdf_path = fetch_and_create_pdf(url)
if pdf_path:
logger.info(f"返回的PDF文件路径{pdf_path}")
return True, pdf_path
else:
# 如果生成失败返回一个默认的PDF路径
default_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "default.pdf")
logger.info(f"PDF生成失败返回默认路径: {default_path}")
return False, default_path
except Exception as e:
logger.error(f"生成PDF路径时出错: {e}")
# 返回一个默认路径
default_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "default.pdf")
return False, default_path
if __name__ == "__main__":