3

Python爬虫编程思想(42):XPath实战:匹配属性

 2 years ago
source link: https://blog.csdn.net/nokiaguy/article/details/120678988
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.
neoserver,ios ssh client

目录

1. 属性匹配与获取

2. 多属性匹配


1. 属性匹配与获取

        在前面的例子中只是根据节点名称进行匹配,其实XPath的匹配功能远不止如此,比较常用的匹配就是根据属性值来选取节点。引用属性值需要在属性名前面加@,如@class表示class属性。XPath的过滤条件需要放到一对中括号([...])中,如'//a[@class="item1"]'表示过滤所有class属性值为item1的<a>节点。如果不将属性引用放在[...]中,就是获取属性值,如&


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK