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}")
相关推荐
win4r1 天前
🚀彻底改写浏览器自动化!ChatGPT Atlas浏览器深度评测:Agent模式自动操作网页太疯狂!跨网页理解+长文秒懂+图片识别,论文工作流被改写!看完你会
chatgpt·aigc·openai
一点一木1 天前
ChatGPT Atlas 发布:把 AI 直插进浏览器的一次重构
人工智能·chatgpt·浏览器
产业家5 天前
Sora 后思考:从 AI 工具到 AI 平台,产业 AGI 又近了一步
人工智能·chatgpt·agi
weixin_519535775 天前
从ChatGPT到新质生产力:一份数据驱动的AI研究方向指南
人工智能·深度学习·机器学习·ai·chatgpt·数据分析·aigc
尽兴-6 天前
【10 分钟!M4 Mac mini 离线部署「私有 ChatGPT」完整实录】
macos·ai·chatgpt·大模型·ollama·私有化
七牛云行业应用6 天前
100美元成本复现ChatGPT:nanochat全栈技术栈深度剖析
chatgpt·开源项目·nanochat·karpathy·lm训练
小虚竹and掘金7 天前
GPT-5-Codex 发布!claude编程王位即将不保?国内直接使用
chatgpt
007tg7 天前
OpenAI推出即时支付功能,ChatGPT将整合电商能力|技术解析与行业影响
chatgpt
马拉AI7 天前
Andrej Karpathy 发布新项目 nanochat:一个从零开始构建的极简全栈式 ChatGPT 克隆
chatgpt
神码小Z7 天前
特斯拉前AI总监开源的一款“小型本地版ChatGPT”,普通家用电脑就能运行!
人工智能·chatgpt