find the CSS path (ancestor tags) in HTML using python
<p>I want to get all the ancestor div tags where I match a text. So for example if the html looks like <a href="http://i.stack.imgur.com/aePNZ.png" rel="nofollow">HTML snippet</a></p>

<p>And i'm searching for "Earl E. Byrd". I wanna get a list which contains {"buyer-info","buyer-name"}</p>

<p>This is what i did </p>

<pre><code>r=requests.get(self.url,verify='/path/to/certfile')
                soup = BeautifulSoup(r.text,"lxml")
                divTags = soup.find_all('div')
</code></pre>

<p>How should I proceed ?</p>

<p>A solution using an <a href="/questions/tagged/xpath" class="post-tag" title="show questions tagged &#39;xpath&#39;" rel="tag">xpath</a> expression :</p>

<pre><code>//div[@title="buyer-info"]/div[text() = "Carlson Busses"]/ancestor::div
</code></pre>

python web-scraping bs4