Skip to content

Commit

Permalink
Merge pull request #1 from ybch14/dev
Browse files Browse the repository at this point in the history
修复parse_web中未找到搜索数量的报错
  • Loading branch information
yuyijiong committed Jun 13, 2024
2 parents c187609 + 7abcb58 commit 15a8db8
Showing 1 changed file with 7 additions and 4 deletions.
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

0 comments on commit 15a8db8

Please sign in to comment.