所以我想做的是使用python来解析有关所有引号的文章。我用漂亮的汤从网站上提取了html,现在我正尝试使用split打印引号中的所有内容。
例如,来自:
I like quotes but especially "have problems"
去
have problems
答案 0 :(得分:2)
或re.findall(r'"([^"]*)"',s)
,演示:
>>> import re
>>> s='I like quotes but especially "have problems"'
>>> re.findall(r'"([^"]*)"',s)
['have problems']
>>>
regex
是您的好朋友,
https://docs.python.org/3/howto/regex.html
https://docs.python.org/3/library/re.html?highlight=findall#re.findall
答案 1 :(得分:1)
您可以切片str.split
返回的列表:
s = 'I like quotes but especially "have problems" and "need more quotes"'
s.split('"')[1::2]
这将返回:
['have problems', 'need more quotes']