Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正则表达式删除标记Python_Python_Html_Regex - Fatal编程技术网

正则表达式删除标记Python

正则表达式删除标记Python,python,html,regex,Python,Html,Regex,有一个字符串: myString = '<p>Phone Number:</p><p>706-878-8888</p>' myString='电话号码:706-878-8888' 试图正则化所有HTML标记,在本例中为段落 谢谢 使用: 电话号码:706-878-8888> '电话号码:706-878-8888' 如果您只想删除标记,那么使用re是一个很好的解决方案。但是,如果您想做一些更复杂的事情(包括HTML解析),我建议您进行研究。使用

有一个字符串:

myString = '<p>Phone Number:</p><p>706-878-8888</p>'
myString='电话号码:

706-878-8888

'
试图正则化所有HTML标记,在本例中为段落

谢谢

使用:

电话号码:

706-878-8888

> '电话号码:706-878-8888' 如果您只想删除标记,那么使用
re
是一个很好的解决方案。但是,如果您想做一些更复杂的事情(包括HTML解析),我建议您进行研究。

使用注释中指出的:

>>> from BeautifulSoup import BeautifulSoup
>>> BeautifulSoup(myString).text
u'Phone Number:706-878-8888'

不要使用正则表达式解析(X)HTML。使用解析器。我会直接链接到这个问题的答案@Hamish::-PPerfect!我一直在尝试属性“string”而不是文本。非常感谢!
>>> from BeautifulSoup import BeautifulSoup
>>> BeautifulSoup(myString).text
u'Phone Number:706-878-8888'