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}")
相关推荐
Want5955 小时前
从ChatGPT到GPT-4:大模型如何重塑人类认知边界?
chatgpt·aigc
Awesome Baron12 小时前
《Learning Langchain》阅读笔记8-RAG(4)在vector store中存储embbdings
python·jupyter·chatgpt·langchain·llm
张申傲12 小时前
多模态(3):实战 GPT-4o 视频理解
人工智能·chatgpt·aigc·多模态
SLY司赖16 小时前
大模型应用开发之LLM入门
语言模型·chatgpt·llm
古希腊掌管学习的神1 天前
[LangGraph教程]LangGraph04——支持人机协作的聊天机器人
人工智能·语言模型·chatgpt·机器人·agent
鸿蒙布道师1 天前
OpenAI为何觊觎Chrome?AI时代浏览器争夺战背后的深层逻辑
前端·人工智能·chrome·深度学习·opencv·自然语言处理·chatgpt
AIGC大时代1 天前
高质量学术引言如何妙用ChatGPT?如何写提示词
人工智能·深度学习·chatgpt·学术写作·chatgpt-o3·deep reaserch
盈达科技3 天前
[盈达科技】GEO(生成式引擎优化)实战指南:从认知重构、技术落地到内容突围的三维战略
人工智能·chatgpt
Feel_狗焕4 天前
transformer架构详解由浅入深-大模型入坑笔记真的很详细
chatgpt·llm
赵钰老师4 天前
【大语言模型DeepSeek+ChatGPT+python】最新AI-Python机器学习与深度学习技术在植被参数反演中的核心技术应用
人工智能·arcgis·语言模型·chatgpt·数据分析