Python实现将Html转换为UBB,pythonhtml转换ubb,python实现html
Python实现将Html转换为UBB,pythonhtml转换ubb,python实现html
python实现html转UBB,通常大家都是UBB转正则,我有点特殊需求需要将html转为UBB,完全用正则表达式实现的。 可以转换部分标签,如下python代码:
import redef Html2UBB(content): #以下是将html标签转为ubb标签 pattern = re.compile( '<a href=\"([sS]+?)\"[^>]*>([sS]+?)</a>',re.I) content = pattern.sub(r'[url=1]2[/url]',content) pattern = re.compile( '<img[^>]+src=\"([^\"]+)\"[^>]*>',re.I) content = pattern.sub(r'[img]1[/img]',content) pattern = re.compile( '<strong>([sS]+?)</strong>',re.I) content = pattern.sub(r'[b]1[/b]',content) pattern = re.compile( '<font color=\"([sS]+?)\">([sS]+?)</font>',re.I) content = pattern.sub(r'[1]2[/1]',content) pattern = re.compile( '<[^>]*?>',re.I) content = pattern.sub('',content) #以下是将html转义字符转为普通字符 content = content.replace('<','<') content = content.replace('>','>') content = content.replace('”','”') content = content.replace('“','“') content = content.replace('"','"') content = content.replace('©','?') content = content.replace('®','?') content = content.replace(' ',' ') content = content.replace('—','—') content = content.replace('–','–') content = content.replace('‹','?') content = content.replace('›','?') content = content.replace('…','…') content = content.replace('&','&') return content
相关内容
- python使用PyPDF解析PDF文件,pythonpypdf解析pdf,pyPDF模块提供
- python 多进程使用Queue通信的例子,pythonqueue,如下代码:
- python使用Connection实现多进程之间通信,pythonconnection,在
- python使用BeautifulSoup解析html获得网站的百度收录量,,
- 使用python对png图片文件做base64编码,,有时候我们需要使
- python根据进程名杀死进程,python杀死进程,在linux/unix平
- Python @staticmethod 和 @classmethod之间的区别,,使用@static
- Python 数组分隔总结,python数组分隔,初学Python被它的数
- 在python中调用外部命令,python调用外部命令,在python中有
- Python内存调优,python调优,在python中可以使用
评论关闭