In the Selenium Doc they have used ^, $ and * previous to the = operators the in the below code: But none of them are explained why such special symbols
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>]
Those are substring matching attribute selectors adapted from CSS 3:
=matches only if the given value is equal to the element’s attribute value.^=matches only if the given value is a prefix of the element’s attribute value.$=matches only if the given value is a suffix of the element’s attribute value.*=matches only if the given value is contained in the element’s attribute value.In your case:
a[href="http://example.com/elsie"]selects anyaelement whosehrefattribute value is equal tohttp://example.com/elsie.a[href^="http://example.com/"]selects anyaelement whosehrefattribute value starts withhttp://example.com/.a[href$="tillie"]selects anyaelement whosehrefattribute value ends withtillie.a[href*=".com/el"]selects anyaelement whosehrefattribute value contains.com/el.