Why does BeautifulSoup work the second time parsing, but not the first
<p>This is the <code>ResultSet</code> of running <code>soup[0].find_all('div', {'class':'font-160 line-110'})</code>:  </p>

<pre><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;    
    &lt;a class="no-underline group-ib color-inherit"
    href="/en/ais/details/ports/959"&gt;
    &lt;span class="text-default"&gt;CN&lt;/span&gt;&lt;span class="text-default text-darker"&gt;XMN
&lt;/span&gt;
&lt;/a&gt;
&lt;/div&gt;]
</code></pre>

<p>In an attempt to pull out <code>XIAMEN [CN]</code> after <code>title</code> I could not use <code>a[0].find('div')['title]</code> (where <code>a</code> is the above <code>BeautifulSoup ResultSet</code>). However, if I copy and paste that HTML as a new string, say, </p>

<pre><code>b = '''&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></pre>

<p>Then do: </p>

<pre><code>&gt;&gt;soup = BeautifulSoup(b, 'html.parser')
&gt;&gt;soup.find('div')['title']
&gt;&gt;XIAMEN [CN] #prints contents of title
</code></pre>

<p>Why do I have to reSoup the Soup? Why doesn't this work on my first search?</p>

<p>Edit, origin of <code>soup</code>:</p>

<p>I have a list of <code>urls</code> that I'm going though via <code>grequests</code>. One of the things I'm looking for is that <code>title</code> that contains <code>XIAMEN [CN]</code>. </p>

<p>So <code>soup</code> was created when I did </p>

<pre><code>soup = []
    with i in range(2) #number of pages parsed
     rawSoup = BeautifulSoup(response[i].content, 'html.parser')   
     souporigin = rawSoup.find_all('div', {'class': 'bg-default bg-white no-    snippet-hide'})
    soup.append(souporigin)
</code></pre>

<p>The urls are</p>

<pre><code>[
'http://www.marinetraffic.com/en/ais/details/ships/shipid:564352/imo:9643752/mmsi:511228000/vessel:DE%20MI',
'http://www.marinetraffic.com/en/ais/details/ships/shipid:3780155/imo:9712395/mmsi:477588800/vessel:SITC%20GUANGXI?cb=2267'
]
</code></pre>

<p>You use wrong selection.</p>

<p>Selection <code>soup[0].find_all('div', {'class':'font-160 line-110'})</code> finds <code>&lt;div&gt;</code> and you can even see <code>&lt;div&gt;</code> when you print it. But when you add <code>.find()</code> it starts searching <strong>inside</strong> <code>&lt;div&gt;</code> - so <code>.find('div')</code> tries to find new <code>div</code> in current <code>div</code></p>

<p>You need </p>

<pre><code>a[0]['title']
</code></pre>

<hr>

<p>When you create new soup then main/root element is not <code>div</code> but <code>[document]</code> and <code>div</code> is its child (<code>div</code> is inside main "tag") so you can use <code>find('div')</code>.</p>

<pre><code>&gt;&gt;&gt; a[0].name
div

&gt;&gt;&gt; soup = BeautifulSoup(b, 'html.parser')
&gt;&gt;&gt; soup.name
[document]
</code></pre>

python html beautifulsoup