Aru*_*hit 3 python beautifulsoup python-2.7
在他们使用的Selenium Doc中^,$以及*之前的=运算符在下面的代码中:但是没有一个被解释为什么这样的特殊符号
soup.select('a[href="http://example.com/elsie"]')
# [<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>]
soup.select('a[href^="http://example.com/"]')
# [<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>,
# <a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>,
# <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>]
soup.select('a[href$="tillie"]')
# [<a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>]
soup.select('a[href*=".com/el"]')
# [<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>]
Run Code Online (Sandbox Code Playgroud)
=仅当给定值等于元素的属性值时才匹配.^=仅当给定值是元素属性值的前缀时才匹配.$=仅当给定值是元素属性值的后缀时才匹配.*=仅当给定值包含在元素的属性值中时才匹配.在你的情况下:
a[href="http://example.com/elsie"]选择属性值等于的任何a元素.hrefhttp://example.com/elsiea[href^="http://example.com/"]选择属性值a以其href开头的任何元素http://example.com/.a[href$="tillie"]选择属性值a以其href结尾的任何元素tillie.a[href*=".com/el"]选择属性值包含的任何a元素.href.com/el| 归档时间: |
|
| 查看次数: |
127 次 |
| 最近记录: |