python html转markdown
html2text
# pip3 install html2text
import html2text as ht
text_maker = ht.HTML2Text()
text_maker.bypass_tables = False
htmlfile = requests.get(URL)
htmlfile.encoding = 'utf-8'
soup = BeautifulSoup(htmlfile.text, 'html.parser')
content = soup.find(class_='post').text
text = text_maker.handle(content)
tomd
import tomd
htmlfile = requests.get(URL)
htmlfile.encoding = 'utf-8'
soup = BeautifulSoup(htmlfile.text, 'html.parser')
content = soup.find(class_='post').text
text = tomd.Tomd(content).markdown
pypandoc
import pypandoc
output = pypandoc.convert_text(
htmlTxt,
'md', format='html',
extra_args=['--atx-headers'])
markdownload
本文介绍了将HTML内容转换为Markdown格式的三种方法:html2text、tomd和pypandoc。通过这些库,可以轻松地将网页内容或带有HTML标记的文本转化为Markdown,便于阅读和编辑。
6125

被折叠的 条评论
为什么被折叠?



