3

Python爬虫编程思想(59): 用Beautiful Soup CSS选择器获取属性值与文本

 2 years ago
source link: https://blog.csdn.net/nokiaguy/article/details/121043948
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爬虫编程思想(59): 用Beautiful Soup CSS选择器获取属性值与文本

        由于select方法同样会返回Tag对象的集合,所以可以使用Tag对象的方式获取节点属性值和文本内容。获取属性值可以使用attrs,也可以直接使用[...]方式引用节点的属性。获取节点的文本内容可以使用get_text方法,也可以使用string属性。

下面的例子使用CSS选择器选取特定的a节点,并获取a节点的href属性值和文本内容。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK