【发布时间】:2017-05-08 07:59:08
【问题描述】:
from bs4 import BeautifulSoup
list = (glob.glob("/home/anastasiya/PycharmProjects/bachelor/rutexts/*.xhtml"))
for text in list:
print(text)
with open(text, "r", encoding="windows-1251") as file:
with open("ruscorpus.txt", "a") as file2:
for line in file:
soup = BeautifulSoup(line, "lxml")
if soup.w is not None:
file2.write("{wort}\t{gr}\t{lex}\n".format(
lex=soup.w.ana.get('lex'),
gr=test(soup.w.ana.get('gr')),
wort=soup.w.contents[-1]))
我尝试从 xml 中获取一些信息。格式是这样的。 该程序运行,但如果我们在一个 w 标签中有 2 个单词,它将第一个作为带有整个标签的输出:
【问题讨论】:
-
为什么要明智地阅读
xml数据线?
标签: python xml beautifulsoup