csdn上有好用的内容,我们怎么将它们加到 onenote 里吃灰呢。
html_2">一、创建 新html
create_html.py
import sysdef create_html_file(filename):# 检查是否提供了文件名if not filename:print("请提供HTML文件名")return# 创建HTML内容html_content = f"""<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>{filename}</title>
</head>
<body>
</body>
</html>
"""# 写入文件with open(filename, 'w', encoding='utf-8') as file:file.write(html_content)print(f"文件 {filename} 已创建")if __name__ == "__main__":if len(sys.argv) != 2:print("用法: python create_html.py <html文件名>")else:create_html_file(sys.argv[1])
使用命令 创建html
二、网页找内容
content_views 里就是真正内容了。
copy-> copy outerhtml
粘贴到 创建的html 的 body 中。
三、替换内容
modify_html.py
import sys
import os
from bs4 import BeautifulSoupdef modify_html_file(filename):# 检查是否提供了文件名if not filename:print("请提供HTML文件名")return# 查找当前目录下的HTML文件if not os.path.exists(filename):print(f"文件 {filename} 不存在")return# 读取HTML内容with open(filename, 'r', encoding='utf-8') as file:html_content = file.read()# 使用BeautifulSoup解析HTMLsoup = BeautifulSoup(html_content, 'html.parser')# 替换指定的divdivs_to_remove = soup.find_all('div', class_='hljs-button {2}')for div in divs_to_remove:new_tag = soup.new_tag('p') # 创建一个新的标签new_tag.string = "----------------------------------------------------------------------------------------------------------------"div.replace_with(new_tag) # 替换原标签# 替换指定的divdivs_to_remove = soup.find_all('div', class_='hide-preCode-box')for div in divs_to_remove:# 在原位置添加“------------------”new_tag = soup.new_tag('p') # 创建一个新的标签new_tag.string = "----------------------------------------------------------------------------------------------------------------"div.replace_with(new_tag) # 替换原标签# 删除指定的ululs_to_remove = soup.find_all('ul', class_='pre-numbering')for ul in uls_to_remove:ul.decompose()# 写回修改后的HTML内容with open(filename, 'w', encoding='utf-8') as file:file.write(str(soup))print(f"文件 {filename} 已修改")if __name__ == "__main__":if len(sys.argv) != 2:print("用法: python modify_html.py <html文件名>")else:modify_html_file(sys.argv[1])
因为拷贝的 html 有以下内容
太不美观了,要把它们删除掉
再打开就好看多了
现在 html 的内容也可以直接复制到 onenote 里吃灰了