3

Python爬虫编程思想(57): Beautiful Soup中CSS选择器的基本用法

 2 years ago
source link: https://blog.csdn.net/nokiaguy/article/details/120804682
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Python爬虫编程思想(57): Beautiful Soup中CSS选择器的基本用法

        Beautiful Soup还提供了另外一种选择器,那就是CSS选择器。对Web开发熟悉的读者相信对CSS选择器一定不陌生。如果对CSS选择器不熟悉,可以参考http://www.w3school.com.cn/cssref/css_selectors.ASP页面的内容。

        使用CSS选择器需要使用Tag对象的select方法,该方法接收一个字符串类型的CSS选择器。常用的CSS选择器有如下几个。

  1. .classname:选取样式名为classname的节点。也就是class属性值是classname的节点。
  2. nodename:选取节点名为nodename的节点。
  3. #idname:选取id属性值为idname的节点。

下面的例子使用CSS选取根据class属性、节点名称和id属性查询特定的节点。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK