获取CSDN文章内容并转换为markdown文本的python
更新时间:2020年09月06日 23:36:34 作者:tansty
这篇文章主要介绍了自己写的小工具,可以直接获取csdn文章并转换为markdown格式,需要的朋友可以参考下
自己写的小工具,可以直接获取csdn文章并转换为markdown格式
效果图
核心代码
from PySide2.QtWidgets import QApplication,QMainWindow,QPushButton,QPlainTextEdit,QMessageBox import re import parsel import tomd import requests class CSDN(): def __init__(self): self.windows = QMainWindow() self.windows.resize(450, 300) self.windows.setWindowTitle("轻松获取csdn文章--by tansty") self.setup_ui() self.set_connect() def set_connect(self): #设置建立联系 self.button.clicked.connect(self.spider_csdn) def setup_ui(self): #设置ui界面的建立 self.button = QPushButton(self.windows) self.button.resize(100, 100) self.button.move(150, 150) self.button.setText("获取文章") self.text = QPlainTextEdit(self.windows) self.text.setPlaceholderText("请输入需要获取文章的链接") self.text.resize(450, 100) def spider_csdn(self): # 目标文章的链接 title_url=self.text.toPlainText() MessageBox = QMessageBox(self.windows) if not title_url: MessageBox.critical(self.windows, "错误", "请输入网址") return head={"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36 Edg/84.0.522.52" } html=requests.get(url=title_url,headers=head).text page=parsel.Selector(html) #创建解释器 title=page.css(".title-article::text").get() res = re.compile("[^\u4e00-\u9fa5^a-z^A-Z^0-9]") restr = '' res.sub(restr, title) content=page.css("article").get() content=re.sub("<a.*?a>","",content) content = re.sub("<br>", "", content) texts=tomd.Tomd(content).markdown #转换为markdown 文件 with open(title+".md",mode="w",encoding="utf-8") as f: f.write("#"+title) f.write(texts) MessageBox.information(self.windows,"正确","获取文章完成") if __name__ == '__main__': app = QApplication() csdn=CSDN() csdn.windows.show() app.exec_()
文件打包下载 链接: https://pan.baidu.com/s/1R6RcrDagwf1vWzmRCBja4w 提取码: ug6n
您可能感兴趣的文章:
- Python3自动生成MySQL数据字典的markdown文本的实现
- python使用html2text库实现从HTML转markdown的方法详解
- 解决python Markdown模块乱码的问题
- 如何用Python实现简单的Markdown转换器
- python导出chrome书签到markdown文件的实例代码
- python 自动化将markdown文件转成html文件的方法
- 使用Python来开发Markdown脚本扩展的实例分享
- python3处理word文档实例分析
- Python word文本自动化操作实现方法解析
- Python操作word文档插入图片和表格的实例演示
- Python实现Word文档转换Markdown的示例
相关文章
tensorflow中tf.reduce_mean函数的使用
这篇文章主要介绍了tensorflow中tf.reduce_mean函数的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2020-04-04
最新评论