Test for presence of specific text in tag with scrapy
<p>I'm interested in testing for the presence of specific text (an error message) on pages that I'm scraping. I have the following working statement:</p>

<pre><code>   not_found=response.selector.xpath('//*[@id="Error"]/font[contains(text(),"is not found")]')
</code></pre>

<p>I can see that their is a boolean test mentioned in the docs (<a href="https://doc.scrapy.org/en/0.12/topics/selectors.html#scrapy.selector.XPathSelector.__nonzero__" rel="nofollow">https://doc.scrapy.org/en/0.12/topics/selectors.html#scrapy.selector.XPathSelector.<strong>nonzero</strong></a>) but I'm not sure if I can apply it here to do something like (pseudocode):</p>

<pre><code>    if __nonzero__(not_found):
</code></pre>

<p>I was having trouble finding it to import so have not been able to test properly. How can I get this working?</p>

<p>Python doc: <a href="https://docs.python.org/2/reference/datamodel.html#object.__nonzero__" rel="nofollow"><code>__nonzero__</code></a></p>

<p>It is used automatically when you do <code>bool(not_found)</code><br>
and <code>bool()</code> is use automatically when you do <code>if not_found:</code></p>

<hr>

<p>You don't have to use <code>__nonzero__</code> and you shouldn't use it directly (because you have <code>bool()</code> for this) but if you really have to then it should be <code>not_found.__nonzero__()</code></p>

python scrapy