小编she*_*hem的帖子

在 beautiful soup 中使用 lambda 函数

尝试匹配包含某些文本的链接。我正在做

links = soup.find_all('a',href=lambda x: ".org" in x)
Run Code Online (Sandbox Code Playgroud)

但这会引发 TypeError: argument of type 'NoneType' is not iterable。

正确的做法显然是

links = soup.find_all('a',href=lambda x: x and ".org" in x)
Run Code Online (Sandbox Code Playgroud)

x and为什么这里需要额外的?

python beautifulsoup

4
推荐指数
1
解决办法
7544
查看次数

标签 统计

beautifulsoup ×1

python ×1