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}")
相关推荐
云边有个稻草人15 小时前
DeepSeek与ChatGPT:会取代搜索引擎和人工客服的人工智能革命
人工智能·搜索引擎·chatgpt·deepseek
陈敬雷-充电了么-CEO兼CTO1 天前
DeepSeek核心算法解析:如何打造比肩ChatGPT的国产大模型
人工智能·神经网络·自然语言处理·chatgpt·大模型·aigc·deepseek
我们的五年2 天前
DeepSeek 和 ChatGPT 在特定任务中的表现:逻辑推理与创意生成
人工智能·chatgpt·ai作画·deepseek
浮华落定2 天前
DeepSeek+即梦 做AI视频
人工智能·chatgpt·音视频
奇偶变不变2 天前
过于依赖chatgpt编程会有哪些弊端?
人工智能·chatgpt
mygodalien3 天前
Win7编译GPU版llama.cpp部署deepseek-r1等大模型记录
人工智能·机器学习·chatgpt·llama
赵钰老师3 天前
【科研创新与智能化转型】AI智能体开发与大语言模型的本地化部署、优化技术
人工智能·语言模型·自然语言处理·chatgpt·数据分析
qq_433502183 天前
Flowith.io 初探:DeepSeek-R1免费用,用画布式 AI 提升效率和创意
人工智能·经验分享·chatgpt·学习方法·ai写作·知识库·画布
月光技术杂谈3 天前
关于DeepSeek与ChatGPT等模型的原始训练数据
chatgpt·语料库·训练数据·ai模型·数据分类·deepseek·训练样本