3

彼らが使用したSeleniumDoc^では、以下のコードの演算子の前に:しかし、なぜそのような特別な記号が使用されているのかは説明されていません。$*=

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>]
4

2 に答える 2

7

これらは、CSS 3 から適用された部分文字列一致属性セレクターです。

  • =指定された値が要素の属性値と等しい場合にのみ一致します。
  • ^=指定された値が要素の属性値のプレフィックスである場合にのみ一致します。
  • $=指定された値が要素の属性値のサフィックスである場合にのみ一致します。
  • *=指定された値が要素の属性値に含まれている場合にのみ一致します。

あなたの場合:

  • a[href="http://example.com/elsie"]属性値が と等しい任意のa要素を選択します。hrefhttp://example.com/elsie
  • a[href^="http://example.com/"]属性値が で始まる任意のa要素を選択します。hrefhttp://example.com/
  • a[href$="tillie"]属性値が で終わる任意のa要素を選択します。hreftillie
  • a[href*=".com/el"]属性値に が含まれる任意のa要素を選択します。href.com/el
于 2013-01-05T12:34:57.750 に答える
3

表示されるのは CSS セレクターです。

http://www.w3.org/TR/css3-selectors/#selectors

于 2013-01-05T12:34:31.147 に答える