Python:如何将降价格式的文本转换为文本 [英] Python : How to convert markdown formatted text to text

查看:83
本文介绍了Python:如何将降价格式的文本转换为文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将降价文本转换为纯文本格式,以便在我的网站上显示摘要.我想要python中的代码.

I need to convert markdown text to plain text format to display summary in my website. I want the code in python.

推荐答案

该模块将帮助您完成以下操作:

This module will help do what you describe:

http://www.freewisdom.org/projects/python-markdown/Using_as_a_Module

将降价标记转换为HTML后,您可以使用HTML解析器来清除纯文本.

Once you have converted the markdown to HTML, you can use a HTML parser to strip out the plain text.

您的代码可能看起来像这样:

Your code might look something like this:

from BeautifulSoup import BeautifulSoup
from markdown import markdown

html = markdown(some_html_string)
text = ''.join(BeautifulSoup(html).findAll(text=True))

这篇关于Python:如何将降价格式的文本转换为文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆