ChatGPT辅助编程,一次有益的尝试

如果大家想学习PCIe,搜索网上的信息,大概率会看到chinaaet上Felix的PCIe扫盲系列的博文

Felix-PCIe扫盲

每次看这个系列博文的时候,我都在想有没有什么方法可以把这个系列的博文都保存到一个pdf文件中,这样方便阅读。于是有了下面使用ChatGPT进行辅助编程的内容:

我是使用知乎上的引用Felix博文网页为根开始工作的:

PCIe扫盲系列博文

下面的链接是我和ChatGPT对话的详细内容:

Convert webpage to PDF.https://chat.openai.com/share/812bae9d-76bb-4701-8379-cd200aa45ad0

生成的可用python代码如下:

python 复制代码
import requests
from bs4 import BeautifulSoup
import re
from urllib.parse import unquote
import pdfkit
from PyPDF2 import PdfMerger


url = "https://zhuanlan.zhihu.com/p/655702770"

# 发送GET请求并获取页面内容
response = requests.get(url)
html_content = response.text

# 使用BeautifulSoup解析HTML
soup = BeautifulSoup(html_content, 'html.parser')

# 提取所有的超链接
links = soup.find_all('a', href=True)
target_regex = re.compile(r'target=(.+)')

target_html = []

# 输出所有链接
for link in links:
    # 获取原始的 href 属性
    raw_href = link['href']

    # 使用 unquote 处理 URL 编码
    decoded_href = unquote(raw_href)

    match = target_regex.search(decoded_href)

    if match:
        target_content = match.group(1)
        print(target_content)
        target_html.append(target_content)

config = pdfkit.configuration(wkhtmltopdf='/usr/bin/wkhtmltopdf')

output_pdf_path = "output.pdf"

# Create a PDF merger object
pdf_merger = PdfMerger()

# Generate PDFs and add them to the merger
for i, target_url in enumerate(target_html):
    pdf_file_path = f"output_{i}.pdf"
    pdfkit.from_url(target_url, pdf_file_path, configuration=config)
    pdf_merger.append(pdf_file_path)

# Write the combined PDF to the output file
with open(output_pdf_path, 'wb') as output_pdf:
    pdf_merger.write(output_pdf)

print(f"Combined PDF saved to {output_pdf_path}")
相关推荐
智算菩萨1 天前
2025通用ChatGPT Agent架构综述:从工具调用、工作流编排到可观测与安全闭环
安全·chatgpt·架构
北冥有一鲲2 天前
LangChain 框架前世今生:从“万能接口”到“AI 应用全家桶”
人工智能·chatgpt·langchain
rockingdingo3 天前
0-1教程 ChatGPT Apps Store应用提交教程——和MCP开发部署
人工智能·chatgpt·chatgpt-app
idkmn_4 天前
Agentic AI 基础概念
人工智能·python·深度学习·chatgpt·langchain
视觉&物联智能5 天前
【杂谈】-边缘计算竞赛:人工智能硬件缘何超越云端
人工智能·ai·chatgpt·aigc·边缘计算·agi·deepseek
不会计算机的g_c__b5 天前
HuggingGPT深度解析:当ChatGPT遇上HuggingFace,打造AI世界的“万能工具箱”
人工智能·chatgpt
梁辰兴5 天前
OpenAI更新ChatGPT Images:生成速度最高提升4倍,原生多模态模型
人工智能·科技·ai·chatgpt·大模型·openai·图像生成
感谢地心引力5 天前
【AI】免费的代价?Google AI Studio 使用指南与 Cherry Studio + MCP 实战教程
人工智能·ai·google·chatgpt·gemini·mcp·cherry studio
Ztop5 天前
没有发布会,GPT Image 1.5 凌晨发布,实测与Nano Banana2相比,各有优势,但也一言难尽...
gpt·chatgpt
Java后端的Ai之路6 天前
【智能体搭建平台篇】-Dify部署方案介绍
人工智能·chatgpt·aigc·ai编程