I’m trying to use the PHP Simple DOM Parser to pull information from a website and it isn’t working for me.
Specifically i am trying to get the:
- 5-day prediction
- 1-month prediction
values from the top of the page.
i am trying to grab the results from this div _ngcontent-coincodex-c2362887433 but not able to extract the data.
no errors encountered. Just not able to get the intended value.
This is my code.
require_once 'simple_html_dom.php';
$url = 'https://coincodex.com/crypto/bad-idea-ai/price-prediction';
$html = file_get_html($url);
foreach($html->find('div._ngcontent-coincodex-c2362887433') as $article) {
echo 'Output:' .$article;
}
Grateful if anyone can share with me what I am doing wrong here.
this is the html i m trying to scrape:
<div _ngcontent-coincodex-c2362887433="" placment="top" tooltipclass="tooltip-custom-class" class="prediction-range" aria-describedby="ngb-tooltip-9">
<div _ngcontent-coincodex-c2362887433="">5-Day Prediction
</div>
<div _ngcontent-coincodex-c2362887433="">
<i _ngcontent-coincodex-c2362887433="" appfontawesome="" class="far fa-long-arrow-down">
<svg style="pointer-events: none;" aria-hidden="true" focusable="false" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512" class="svg-inline--fa"><path fill="currentColor" d="M300.3 327.5l-19.6-19.6c-4.8-4.8-12.5-4.7-17.1.2L186 388.8V44c0-6.6-5.4-12-12-12h-28c-6.6 0-12 5.4-12 12v344.8l-77.5-80.7c-4.7-4.8-12.4-4.9-17.1-.2l-19.6 19.6c-4.7 4.7-4.7 12.3 0 17l131.8 131.8c4.7 4.7 12.3 4.7 17 0l131.8-131.8c4.6-4.7 4.6-12.3-.1-17z"></path>
</svg>
</i> $ 0.0₇3329 <!----><!----><!---->
</div><!----><!----><!----><!----><!---->
</div>
2
Answers
You can simplify your scraping by looking for the class
.prediciton-range
, and then grabbing only the elements with unlocked information:Outputs:
Rather than looking for the weird
_ngcontent-coincodex-c2362887433
, which number may change in the future, it is safer to look for something more static.I would recommend looking for the class
prediction-range
like this: