要解决这个问题,你可以使用BeautifulSoup库中的get_text()方法,并通过设置参数exclude来排除引号。
下面是一个示例代码,演示如何使用BeautifulSoup的get_text()方法来获取span标签中的文本,并排除引号:
from bs4 import BeautifulSoup
html = '''
This is a "beautiful" day.
'''
# 创建BeautifulSoup对象
soup = BeautifulSoup(html, 'html.parser')
# 获取span标签中的文本
span_text = soup.find('span', class_='text').get_text(exclude=['"'])
print(span_text)
在上面的示例代码中,我们先创建了一个BeautifulSoup对象,然后使用find()方法找到class为"text"的span标签。最后,我们通过调用get_text()方法并设置exclude参数为['"']来获取span标签中的文本,并排除引号。
运行以上代码,将输出:This is a beautiful day.