gpt4 book ai didi

python - 为 Python 中的类别查询解析 DMOZ 转储

转载 作者:太空宇宙 更新时间:2023-11-04 06:12:15 26 4
gpt4 key购买 nike

我目前正在从事一个项目,该项目涉及查找与某个关键字相关的“知识领域”。我打算用 DMOZ 来做这件事。例如,“布拉德皮特”给出了

Arts: People: P: Pitt, Brad: Fan Pages (10)

Arts: People: P: Pitt, Brad: Articles and Interviews (5)

Arts: People: P: Pitt, Brad (4)

Arts: People: P: Pitt, Brad: Image Galleries (2)

Arts: People: P: Pitt, Brad: Movies (2)

等等……

我有来自 DMOZ 网站的 structure.rdf.u8 转储。有人跟我提过,如果我不需要 URL,只要这个文件就足够了(我不需要网站,只需要与关键字相关的类别)。或者我还需要内容文件吗?

此外,我想知道使用 Python(任何库)解析 structure 文件的最佳方法。我对 XML 没有任何了解,但我对 Python 很在行。

最佳答案

我从 https://github.com/kremso/dmoz-parser 开始并制作了一个简单的主题过滤器: https://github.com/lawrencecreates/dmoz-parser/blob/master/sample.py#L6

class LawrenceFilter:
def __init__(self):
self._file = open("seeds.txt", 'w')

def page(self, page, content):
if page != None and page != "":
topic = content['topic']
if topic.find('United_States/Kansas/Localities/L/Lawrence') > 0 :
self._file.write(page + "\n")
print "found page %s in topic %s" % (page , topic)

def finish(self):
self._file.close()

关于python - 为 Python 中的类别查询解析 DMOZ 转储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18044438/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com