Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.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_Beautifulsoup - Fatal编程技术网

Python 两个跨类之间的内容

Python 两个跨类之间的内容,python,html,beautifulsoup,Python,Html,Beautifulsoup,我试图用BeautifulSoup解析出一个HTML页面,并将其保存为较小的HTML文件。我有两个问题: 1.是否有一种方法可以在两个跨度之间获取内容,例如: <SPAN CLASS="c7">Q2 2016 Apple Inc Earnings Call - Final</SPAN> I am feeling lucky today <SPAN CLASS="c7">Event Brief of Q1 2016 Apple Inc Earn

我试图用BeautifulSoup解析出一个HTML页面,并将其保存为较小的HTML文件。我有两个问题: 1.是否有一种方法可以在两个跨度之间获取内容,例如:

<SPAN CLASS="c7">Q2 2016 Apple Inc Earnings Call - Final</SPAN>  I am feeling lucky today         <SPAN CLASS="c7">Event Brief of Q1 2016 Apple Inc Earnings Call - Final</SPAN>
苹果公司财报电话会议第二季度2016我感到幸运的今天2016事件苹果公司财报电话会议纪要 我正在寻找“我今天感觉很幸运”的文本,并将其保存为

<苹果公司> 2016财报电话会议最终结果。 我一直在beautifulsoup附近玩,但找不到实现这一目标的方法。在此方面的任何帮助都将不胜感激

谢谢您

重新导入
import re

text= '''<SPAN CLASS="c7">Q2 2016 Apple Inc Earnings Call - Final</SPAN> I am feeling lucky today     <SPAN CLASS="c7">Event Brief of Q1 2016 Apple Inc Earnings Call - Final</SPAN>'''
text2= '<span></span>You<span>Hola</span>Hey<span></span>'
pattern = '</(?:SPAN|span)>(?P<content>[\w\d\s]*)<(?:SPAN|span)'

print(re.findall(pattern, text))
print(re.findall(pattern, text2))
2016财报电话会议-我今天感觉幸运,2016苹果公司苹果公司财报电话会议纪要-最后一个 text2='YouHolaHey'
pattern='(?P[\w\d\s]*)是否尝试过使用正则表达式或简单的字符串拆分操作@房车,如果你想,你可以要求版主合并你的两个帐户。不要忘了通过阅读了解stackoverflow是如何工作的。提供了许多很好的提示,这些提示将通过更完整地回答问题来提高您获得好答案的机会。在你的html示例中,这很简单,但是如果不看其他内容,就不可能知道。非常感谢你,我一定会这么做的