Skip to content

Conversation

@NianBroken
Copy link
Contributor

_get_info 函数中,当解析的网页不包含“电子邮箱”等可选字段时,
pending_result 字典中会缺少对应的键。

旧代码的逻辑 ("无" if pending_result.get("电子邮箱:") == "" else pending_result["电子邮箱:"]) 存在缺陷: 当键不存在时,.get() 返回 None,导致条件判断为 False
进而执行 else 分支中的 pending_result["电子邮箱:"]
这种不安全的方括号访问方式直接引发了 KeyError 异常,导致程序崩溃。

本次提交通过将所有类似的数据提取逻辑统一修改为更健壮的 pending_result.get(key) or "无" 模式,

在 `_get_info` 函数中,当解析的网页不包含“电子邮箱”等可选字段时,
`pending_result` 字典中会缺少对应的键。

旧代码的逻辑 `("无" if pending_result.get("电子邮箱:") == "" else pending_result["电子邮箱:"])` 存在缺陷:
当键不存在时,`.get()` 返回 `None`,导致条件判断为 `False`,
进而执行 `else` 分支中的 `pending_result["电子邮箱:"]`,
这种不安全的方括号访问方式直接引发了 `KeyError` 异常,导致程序崩溃。

本次提交通过将所有类似的数据提取逻辑统一修改为更健壮的 `pending_result.get(key) or "无"` 模式,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant