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}")
相关推荐
bryant_meng15 小时前
ChatGPT Desktop Model Evolution (2025): From GPT-4.1 to GPT-5.1
gpt·chatgpt·gpt4·gpt4o·gpt5
一缕82年的清风2 天前
OpenAI 突发 GPT-6.2:Sol 提速 8 倍跑分追平旗舰,但这 1 处暗改会让缓存直接失效!
gpt·chatgpt
死磕音视频2 天前
Businesses in ChatGPT 入门:在 Business Hub 认领商家并完成验证
chatgpt·入门教程·business hub·商家资料
泯泷2 天前
OpenClaw 退潮背后,是 AI 圈“技术自嗨”的终结
人工智能·chatgpt·llm
泯泷2 天前
当"孤独的开发者"成为常态,AI正在悄悄杀死那个我们熟悉的互联网
人工智能·chatgpt·llm
一缕82年的清风5 天前
告别手动搬砖!我是如何搭出一套“AI 全自动自媒体运营系统”,每天 10 分钟铺满 7 大平台的?
chatgpt·claude·gemini
可乐ea6 天前
智能体的模型列表为什么要从三处来源合成:一次让 GPT-6.1 Sol 选不上的发布延迟
人工智能·gpt·chatgpt·智能体框架·模型列表·多源数据合成·客户端工程
dozenyaoyida8 天前
AI与大模型新闻日报 | 2026-11-11
人工智能·chatgpt·大模型·新闻
一缕82年的清风9 天前
Claude Code 跑 DeepSeek 还带自动切号?开源 Magpie 彻底把大厂的协议护城河给拆了!
chatgpt·claude·gemini
Spidermanbaout11 天前
Prompt-Engineering实战-2026年11月2日
人工智能·机器学习·ai·chatgpt·ai编程