How to find an html element using Beautiful Soup and regex strings
<p>I am trying to find the following <code>&lt;li&gt;</code> element in an html document using python 3, beautiful soup and regex strings.</p>

<pre><code>&lt;li style="text-indent:0pt; margin-top:0pt; margin-bottom:0pt;" value="394"&gt;KEANE J.
The plaintiff is a Sri Lankan national of Tamil ethnicity.  While he was a
passenger on a vessel travelling from India to
Australia, that vessel ("the
Indian vessel") was intercepted by an Australian border protection vessel ("the
Commonwealth ship")
in Australia's contiguous
zone&lt;span class="sup"&gt;&lt;b&gt;&lt;a name="fnB313" href="http://www.austlii.edu.au/au/cases/cth/HCA/2015/1.html#fn313"&gt;[313]&lt;/a&gt;&lt;/b&gt;&lt;/span&gt;. 
&lt;/li&gt;
</code></pre>

<p>I have tried using the following <code>find_all</code> function, which returns an empty list.</p>

<pre><code>html.find_all('li', string='KEANE J.')
</code></pre>

<p>I have also tried the <code>find</code> function with regex, which returns a none object:</p>

<pre><code>html.find('li', string=re.compile(r'^KEANE\sJ\.\s'))
</code></pre>

<p>How would I find this element in the html document?</p>

<blockquote>
  <p>it has something to do with the  element present?</p>
</blockquote>

<p>Absolutely, in this case, aside from the text node, the <code>li</code> element has other children. This is documented in the <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#string" rel="nofollow"><code>.string</code> paragraph</a>:</p>

<blockquote>
  <p>If a tag contains more than one thing, then itâs not clear what <code>.string</code> should refer to, so <code>.string</code> is defined to be <code>None</code></p>
</blockquote>

<p>What you can do is to locate the <em>text node itself</em> and then get its parent:</p>

<pre><code>li = html.find(string=re.compile(r'^KEANE\sJ\.\s')).parent
print(li)
</code></pre>

python html regex beautifulsoup