我是一名设计研究员。我有几个.txt文件,其中包含75-100条引语,我已经给这些引语打上了不同的标签,如下所示:
<q 69_A F exercises positive> Well I think it’s very good. I thought that the exercises that Rosy did was very good. I looked at it a few times. I listened and I paid attention but I didn’t really do it on the regular. I didn’t do the exercises on a regular basis. </q>
我将尝试使用beautifulsoup列出所有标签(“69_a”、“练习”、“正面”)。但是,它并没有给我像这样的输出:
69_a
exercises
positive
它给我输出的结果看起来像这样:
q
q
q
q
Finished...
你能帮我修复这个问题吗?我有很多定性数据需要处理。目标是将所有引用导出到一个 .xlsx 文件中,并使用数据透视表进行排序。
from bs4 import BeautifulSoup
file_object = open('Angela_Q_2.txt', 'r')
soup = BeautifulSoup(file_object.read(), "lxml")
tag = soup.findAll('name')
for tag in soup.findAll(True):
print(tag.name)
print('Finished')