前言
原文地址:https://blog.csdn.net/m0_48742971/article/details/123301571,严禁转载。
本文解析get_value_xpaths
方法。
这个方法的作用
Gets a list of xpaths that contain a text truth_value in DOMTree objects.
翻译:从DOM树中获取包含真值(标注数据)的xpath列表
为什么是xpath列表呢?
因为一个字段可以包含多个值,比如作者可以是多个。
1. 参数分析
为了实现这个目标,要传入dom_tree和truth_value,其他参数需要额外解释。
overall_xpath_dict:这是一个在网站范围内收集xpath的容器,它是这样初始化的:
overall_xpath_dict = collections.defaultdict(set)
website:网站名,为了处理特殊网站才传入的
field:字段名,同上
2. 核心逻辑分析
# Iterate all the nodes in the given DOMTree.
for e in dom_tree.iter