您的位置:首页 > 科技 > IT业 > 义乌手工活外发加工网160网_北京比较有名的设计院_移动端seo关键词优化_线上推广怎么做

义乌手工活外发加工网160网_北京比较有名的设计院_移动端seo关键词优化_线上推广怎么做

2025/4/7 22:40:26 来源:https://blog.csdn.net/hu626626/article/details/145708731  浏览:    关键词:义乌手工活外发加工网160网_北京比较有名的设计院_移动端seo关键词优化_线上推广怎么做
义乌手工活外发加工网160网_北京比较有名的设计院_移动端seo关键词优化_线上推广怎么做

csdn上有好用的内容,我们怎么将它们加到 onenote 里吃灰呢。

一、创建 新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 里吃灰了

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com