Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/283.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从一行xml解析文本_Python_Regex_Xml - Fatal编程技术网

如何使用python从一行xml解析文本

如何使用python从一行xml解析文本,python,regex,xml,Python,Regex,Xml,我有一行xml,希望将所有文本部分解析为一个文本列表 text = '<string name="status">Finishing <xliff:g id="number">%d</xliff:g> percent.</string>' 我使用正则表达式来完成这个简单的任务 import re pattern = re.compile(r'>.+<') match = re.findall(pattern, text) match

我有一行xml,希望将所有文本部分解析为一个文本列表

text = '<string name="status">Finishing <xliff:g id="number">%d</xliff:g> percent.</string>'
我使用正则表达式来完成这个简单的任务

import re
pattern = re.compile(r'>.+<')
match = re.findall(pattern, text)

match = ['>Finishing <xliff:g id="number">%d</xliff:g> percent.<']
重新导入

pattern=re.compile(r'>.+Finishing%d%.将您的正则表达式更新到此值

 pattern = re.compile(r'. *?>(.+?)<')

pattern=re.compile(r'.*?>(.+?)谢谢你的建议。我会调查BeautifulSoup
 pattern = re.compile(r'. *?>(.+?)<')