调整格式,去除无效字符

This commit is contained in:
liuwei
2025-02-17 17:06:03 +08:00
parent 5208a08567
commit eaa419878c

View File

@@ -123,24 +123,24 @@ def fetch_and_create_pdf(url):
if content_div:
# 提取文本并将 <br> 标签替换为换行符
post_text = content_div.get_text(separator='\n', strip=True) # 使用 separator='\n' 参数替换 <br> 标签
post_text = content_div.get_text(strip=True) # 使用 separator='\n' 参数替换 <br> 标签
# 查找磁力链接
magnet_links = re.findall(r'magnet:\?[^ ]+', post_text) # 使用正则表达式查找磁力链接
magnet_links =re.findall(r'magnet:\?[^ \u4e00-\u9fff]+', post_text) # 使用正则表达式查找磁力链接
# 添加标题到PDF
content.append(Paragraph(f"标题:\n {post_title}", title_style))
content.append(Paragraph(f"标题:<br /> {post_title}", title_style))
content.append(Spacer(1, 12))
content.append(Paragraph(f"来源URL:\n {post_page_url}\n", normal_style))
content.append(Paragraph(f"来源URL:<br /> {post_page_url}<br />", normal_style))
content.append(Spacer(1, 12))
content.append(Paragraph(f"介绍:\n {post_text}\n", normal_style))
content.append(Paragraph(f"介绍:<br /> {post_text}<br />", normal_style))
content.append(Spacer(1, 12)) # 添加空白区域
# 如果有磁力链接,将其单独加粗并显示
if magnet_links:
for magnet_link in magnet_links:
# 将磁力链接作为加粗的内容显示
content.append(Paragraph(f"Magnet Link:\n <b>{magnet_link}</b>\n\n", normal_style))
content.append(Paragraph(f"Magnet Link:<br /><br /> <b>{magnet_link}</b><br /><br />", normal_style))
content.append(Spacer(1, 12)) # 添加空白区域
# 添加图片