$ pip install beautifulsoup4
Python

安装完成后,我们就可以开始使用Beautiful Soup来提取

通过CSS选择器提取

除了通过标签名提取,Beautiful Soup还支持使用CSS选择器来提取元素。可以使用select()方法来选择符合CSS选择器规则的元素。下面是一个例子:

scripts = soup.select('script')
for script in scripts:
    print(script.text)
Python

在上面的例子中,我们使用select()方法传递一个CSS选择器来选择所有的