Rafael Martins Rafael Martins - 1 year ago 95
HTML Question

Extract the string after title in BeautifulSoup

html result is

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

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

Answer Source
from bs4 import BeautifulSoup

myHTML = 'what you posted above'
soup = BeautifulSoup(myHTML, "html5lib")
title = soup.find('div')['title']

We're just searching for <div> tags here, you'll probably want to be more specific in vivo.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download