Extract the string after title in BeautifulSoup
<p>html result is <code>&lt;div class="font-160 line-110" data-container=".snippet container" data-html="true" data-placement="top" data-template='&amp;lt;div class="tooltip infowin-tooltip" role="tooltip"&amp;gt;&amp;lt;div class="tooltip-arrow"&amp;gt;&amp;lt;div class="tooltip-arrow-inner"&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div class="tooltip-inner" style="text-align: left"&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;' data-toggle="tooltip" title="XIAMEN [CN]"&gt;</code></p>

<p>How do I pull out <code>"XIAMEN [CN]"</code> right after <code>title</code>. I tried <code>find_all('title')</code> but that does not return a match. Nor can I call any from of <code>siblings</code> to traverse my way down the result. I couldn't even get <code>find(text='XIAMEN [CN]')</code> to return anything. </p>

<p>You should use the class or some attribute to select the div, calling <code>find("div")</code> would select the first div on the page,  also <em>title</em> is an attribute not a tag so you need to access the <em>title attribute</em> once you locate the tag. A few of examples of how to be specific and extract the <em>attribute</em>:</p>

<pre><code>html = """&lt;div class="font-160 line-110" data-container=".snippet container" data-html="true" data-placement="top" data-template='&amp;lt;div class="tooltip infowin-tooltip" role="tooltip"&amp;gt;&amp;lt;div class="tooltip-arrow"&amp;gt;&amp;lt;div class="tooltip-arrow-inner"&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;div class="tooltip-inner" style="text-align: left"&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;/div&amp;gt;' data-toggle="tooltip" title="XIAMEN [CN]"&gt;"""

soup = BeautifulSoup(html, "html.parser")

# use the css classes
print(soup.find("div", class_="font-160 line-110")["title"])

# use an attribute value
print(soup.find("div", {"data-container": ".snippet container"})["title"])
</code></pre>

<p>If there is only one div with an attribute, look for the div setting <em>title=True</em>:</p>

<pre><code>soup.find("div", title=True)
</code></pre>

<p>You can also combine the steps, i.e the class and one or more attributes.</p>

python html beautifulsoup