Get recommendation rating from sidebar in Yahoo Finance
corn-flour opened this issue · comments
I am trying to scrape the recommendation rating that is provided in Yahoo Finance.
Example page: https://finance.yahoo.com/quote/BYND/analysis?p=BYND
On the side of the page you can find the recommendation rating as shown below
The structure of the part looks something like this:
When I try to get $html->find('.YDC-Col2'), I instead got some JS code:
When I try to see the value of $html->plaintext, I could see that the value I am looking for is under "recommendationMean"
Hence, I want to know how I could get this value out of $html. Thank you so much in advance.
Issue Label Bot is not confident enough to auto-label this issue. See dashboard for more details.
@bte234 You need to fetch the code with a headless browser first, because the site is using JavaScript to render the page. (
simple_html_dom/tests/SimpleHtmlDomTest.php
Line 433 in 5932093
But sometimes everything looks like a nail because we have the hammer:
<?php
$json = file_get_contents('https://query2.finance.yahoo.com/v11/finance/quoteSummary/BYND?formatted=true&crumb=&lang=en-US®ion=US&modules=financialData&corsDomain=finance.yahoo.com');
$array = json_decode($json, true);
echo $array['quoteSummary']['result'][0]['financialData']['recommendationMean']['raw'];
Happy Coding: 👍
Thank you so much for your response. I was not aware of the API request for that one!