python beautifulsoup search across multiple lines
<p>I am trying to search for the P/E ratio of a finance page, from the input code shown below. So, essentially I am trying to extract '48.98' from the source.
As the structure is same for Market cap, book value, etc. I am unable to frame the correct code for a soup.find </p>

<p>Would be very grateful for the correct structure of the soup.find code. 
I am a newbie and sorry if i am asking something very basic..
Thanks in advance ! </p>

<pre><code>&lt;div class="FL" style="width:210px; padding-right:10px"&gt;
&lt;div class="PA7 brdb"&gt;
&lt;div class="FL gL_10 UC"&gt;MARKET CAP (Rs Cr)&lt;/div&gt;
&lt;div class="FR gD_12"&gt;41,364.28&lt;/div&gt;
&lt;div class="CL"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="PA7 brdb"&gt;
&lt;div class="FL gL_10 UC"&gt;P/E&lt;/div&gt;
&lt;div class="FR gD_12"&gt;**48.98**&lt;/div&gt;
&lt;div class="CL"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="PA7 brdb"&gt;
&lt;div class="FL gL_10 UC"&gt;BOOK VALUE (Rs)&lt;/div&gt;
&lt;div class="FR gD_12"&gt;147.24&lt;/div&gt;
&lt;div class="CL"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="PA7 brdb"&gt;
&lt;div class="FL gL_10 UC"&gt;DIV (%)&lt;/div&gt;
&lt;div class="FR gD_12"&gt;1000.00%&lt;/div&gt;
&lt;div class="CL"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="PA7 brdb"&gt;
&lt;div class="FL gL_10 UC"&gt;Market Lot&lt;/div&gt;
&lt;div class="FR gD_12"&gt;1&lt;/div&gt;
&lt;div class="CL"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="PA7 brdb"&gt;
&lt;div class="FL gL_10 UC"&gt;INDUSTRY P/E&lt;/div&gt;
&lt;div class="FR gD_12"&gt;60.95&lt;/div&gt;
&lt;div class="CL"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>Use the text to find the  div with <em>"P/E"</em> and get the next div:</p>

<pre><code>price = soup.find("div", class_="FL gL_10 UC", text="P/E").find_next("div").text
</code></pre>

<p>If it is always the second div with the css class <em>FR gD_12</em>, you could also just get the first two and extract the second</p>

<pre><code>price = soup.select("div.FR.gD_12", limit=2)[1].text
</code></pre>

python beautifulsoup