"如何在bs4中使用find_all multiple来提取数据?"

8 Replies, 314 Views

大家好!

我觉得在bs4 find_all multiple中,使用一个自定义函数也很有用。

你可以传递一个函数给 `find_all`,这样可以根据条件灵活筛选元素。例如:

```python
def match_class(elem):
return 'class1' in elem.get('class', []) or 'class2' in elem.get('class', [])

soup.find_all(match_class)
```

Messages In This Thread



Users browsing this thread: 1 Guest(s)