Using BeautifulSoup I am trying to scrape MarketWatch
from bs4 import BeautifulSoup
import requests
import pandas
url = "https://www.marketwatch.com/investing/stock/khc/profile"
# Make a GET request to fetch the raw HTML content
html_content = requests.get(url).text
soup = BeautifulSoup(html_content, "lxml")
Now I would like to extract the "P/E Current" and the "Price to Sales Ratio" that in the html are in the class
[...]
<div class="sixwide addgutter">
<div class="block threewide addgutter">
<h2>Valuation</h2>
<div class="section">
<p class="column">P/E Current</p>
<p class="data lastcolumn">19.27</p>
</div>
<div class="section">
<p class="column">P/E Ratio (with extraordinary items)</p>
<p class="data lastcolumn">19.55</p>
</div>
<div class="section">
<p class="column">P/E Ratio (without extraordinary items)</p>
<p class="data lastcolumn">20.00</p>
</div>
<div class="section">
<p class="column">Price to Sales Ratio</p>
<p class="data lastcolumn">1.55</p>
</div>
<div class="section">
<p class="column">Price to Book Ratio</p>
<p class="data lastcolumn">0.75</p>
</div>
[...]
How can I get them?
I use the command
section = soup.findAll('div', {'class' : 'section'})
but then I don't know how to go ahead to get the values I am interested in, can you help?