【发布时间】:2019-04-27 21:38:01
【问题描述】:
我正在尝试将 uspto 的专利 xml 文件解析为 csv。我阅读并尝试了各种方法。最近,我遇到了这个post 但是,我找不到解决方案 您可以找到我要解析的 xml 文件 here 我也试过用beautifulsoup,但没有成功。
这是我使用的代码
import xml.etree.ElementTree as x
path = r"C:\Users\XX\Downloads\ipg190423\ipg190423.xml"
d = []
s = ""
f = open(path)
for l in f:
if l == "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n":
if len(s)>0:
d.append(s)
s = ""
s += l
d.append(s)
index = 0
for xm in d:
root = x.fromstring(xm)
for e in root.iter(tag="patent-"):
print(e)
index += 1
filename = format(str(index) + ".xml")
with open(filename, 'w') as f:
f.write(x.tostring(e))
【问题讨论】:
-
您应该展示一个 xml 示例以及您尝试从中解析的内容。
-
文件确实太大,所以我分享了链接,所以链接中的任何压缩文件都可以,我尝试解析所有信息
-
Edit 你的问题并详细解释,在哪里你卡住了。