Note that there are some explanatory texts on larger screens.

plurals
  1. PONokogiri get elements if exist or not
    primarykey
    data
    text
    <pre><code>Quite simply can you do a conditional scrape, i.e. I want an &lt;a&gt; tag within a parent, and if a &lt;span&gt; is contained within that parent (so the span is holding the &lt;a&gt;, instead of the parent), I still want to drill into the span regardless for the &lt;a&gt; </code></pre> <hr> <p>Hopefully this example will provide enough details.</p> <pre><code>&lt;tr&gt; &lt;td&gt;1989&lt;/td&gt; &lt;td&gt; &lt;i&gt; &lt;a href="/wiki/Always_(1989_film)" title="Always (1989 film)"&gt;Always&lt;/a&gt; &lt;/i&gt; &lt;/td&gt; &lt;td&gt;Pete Sandich&lt;/td&gt; &lt;/tr&gt; </code></pre> <p>I can access the <code>&lt;a&gt;</code> fine using:</p> <p><code>all_links = doca.search('//tr//td//i//a[@href]')</code></p> <p>But what I want to know is can I also add a conditional, so if there is a span surrounding the <code>&lt;a&gt;</code>, can this be put in the search?</p> <pre><code> &lt;tr&gt; &lt;td&gt;1989&lt;/td&gt; &lt;td&gt; &lt;i&gt; &lt;span&gt; &lt;a href="/wiki/Always_(1989_film)" title="Always (1989 film)"&gt;Always&lt;/a&gt; &lt;/span&gt; &lt;/i&gt; &lt;/td&gt; &lt;td&gt;Pete Sandich&lt;/td&gt; &lt;/tr&gt; </code></pre> <p>So is there a way to conditionally grab the <code>&lt;a&gt;</code>, something like so:</p> <p><code>all_links = doca.search('//tr//td//i//?span//a[@href]')</code></p> <p>Where ?span would be a conditional - i.e. if a span is there, then enter that level, and then enter the link.</p> <p>And if no span is there then skip it and just enter the link.</p> <p>Thanks in advance, greatly appreciate any help!</p> <p>Shane</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload