<div><h4id="xpathalsoavailableinlxmlscrapyandbrowsersconsoleviadxxpath">XPath — also available in lxml, Scrapy, and browser's console via <codeclass="python hljs"><spanclass="hljs-string">'$x(<xpath>)'</span></code>:</h4><pre><codeclass="python language-python hljs"><xpath> = //<element>[/ <spanclass="hljs-keyword">or</span> // <element>] <spanclass="hljs-comment"># Child: /, Descendant: //, Parent: /..</span>
<xpath> = //<element>/following::<element><spanclass="hljs-comment"># Next sibling. Also preceding/parent/…</span>
<div><h4id="xpathalsoavailableinlxmlscrapyandbrowsersconsoleviadxxpath">XPath — also available in lxml, Scrapy, and browser's console via <codeclass="python hljs"><spanclass="hljs-string">'$x(<xpath>)'</span></code>:</h4><pre><codeclass="python language-python hljs"><xpath> = //<element>[/ <spanclass="hljs-keyword">or</span> // <element>] <spanclass="hljs-comment"># /<child>, //<descendant>, /../<siblng></span>
<xpath> = //<element>/following::<element><spanclass="hljs-comment"># Next element. Also preceding/parent/…</span>
<condition> = [<sub_cond> [<spanclass="hljs-keyword">and</span>/<spanclass="hljs-keyword">or</span><sub_cond>]] <spanclass="hljs-comment"># For negation use `not(<sub_cond>)`.</span>
<sub_cond> = @<attr>[=<spanclass="hljs-string">"<val>"</span>]<spanclass="hljs-comment"># `text()=`, `.=` match (complete) text.</span>
<sub_cond> = contains(@<attr>, <spanclass="hljs-string">"<val>"</span>) <spanclass="hljs-comment"># Is <val> a substring of attr's value?</span>
<sub_cond> = [//]<element><spanclass="hljs-comment"># Has matching child? Descendant if //.</span>