Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复parse_web中未找到搜索数量的报错 #1

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions baiduspider/parser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ def parse_web(self, content: str, exclude: list) -> dict:
if found:
break
idx_ += 1
num = int(
str(ele.text).strip("百度为您找到相关结果").strip("约").strip("个").replace(",", "")
)
try:
num = int(
str(ele.text).strip("百度为您找到相关结果").strip("约").strip("个").replace(",", "")
)
except:
warnings.warn("未找到搜索结果数量")
# 定义预结果(运算以及相关搜索)
pre_results = []
# 预处理新闻
Expand Down Expand Up @@ -311,7 +314,7 @@ def parse_web(self, content: str, exclude: list) -> dict:
"results": result,
# 最大页数
# "pages": max(pages),
"total": num,
"total": len(result),
}

def parse_web_normal(self, content: str, exclude: list) -> dict:
Expand Down