獲取CSDN文章內(nèi)容并轉(zhuǎn)換為markdown文本的python
更新時間:2020年09月06日 23:36:34 作者:tansty
這篇文章主要介紹了自己寫的小工具,可以直接獲取csdn文章并轉(zhuǎn)換為markdown格式,需要的朋友可以參考下
自己寫的小工具,可以直接獲取csdn文章并轉(zhuǎn)換為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): #設(shè)置建立聯(lián)系 self.button.clicked.connect(self.spider_csdn) def setup_ui(self): #設(shè)置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): # 目標(biāo)文章的鏈接 title_url=self.text.toPlainText() MessageBox = QMessageBox(self.windows) if not title_url: MessageBox.critical(self.windows, "錯誤", "請輸入網(wǎng)址") 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) #創(chuàng)建解釋器 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 #轉(zhuǎn)換為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
相關(guān)文章
能讓你輕松的實現(xiàn)自然語言處理的5個Python庫
今天教大家如何你輕松的實現(xiàn)自然語言預(yù)處理,僅僅需要5個python庫,文中介紹的非常詳細(xì),對正在學(xué)習(xí)python的小伙伴們有很好的幫助,需要的朋友可以參考下2021-05-05tensorflow從ckpt和從.pb文件讀取變量的值方式
這篇文章主要介紹了tensorflow從ckpt和從.pb文件讀取變量的值方式,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-05-05Python 專題六 局部變量、全局變量global、導(dǎo)入模塊變量
本文主要講述python全局變量、局部變量和導(dǎo)入模塊變量的方法。具有很好的參考價值,下面跟著小編一起來看下吧2017-03-03Python機器學(xué)習(xí)NLP自然語言處理基本操作新聞分類
本文是Python機器學(xué)習(xí)NLP自然語言處理系列文章,開始我們自然語言處理 (NLP) 的學(xué)習(xí)旅程. 本文主要學(xué)習(xí)NLP自然語言處理基本操作新聞分類2021-09-09python常用時間庫time、datetime與時間格式之間的轉(zhuǎn)換教程
Python項目中很多時候會需要將時間在Datetime格式和TimeStamp格式之間轉(zhuǎn)化,下面這篇文章主要給大家介紹了關(guān)于python常用時間庫time、datetime與時間格式之間轉(zhuǎn)換的相關(guān)資料,需要的朋友可以參考下2023-02-02