Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Grab Specific Values From Similarweb

I am trying to get some values from similarweb using curls and simple_html_dom, but i can’t grab only the value that i want. It gives me outpt all the page.

I am using the code bellow (this code works for other sites).

<?php

header('Content-Type: text/html; charset=utf-8');
require_once ('url_to_absolute/simple_html_dom.php');

$url = 'https://www.similarweb.com/website/bbc.com/#overview';

$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_REFERER, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201');
$result = curl_exec($curl);
curl_close($curl);

$html = new simple_html_dom();
$html->load_file($result);

$div = $html->find('div.wa-rank-list__value',0)->outertext;

echo $div;

?>

I am trying to capture the value below:
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Please give me a help.

>Solution :

<?php 
header('Content-Type: text/html; charset=utf-8');
$url = 'http://www.similarweb.com/website/bbc.com/#overview';
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_REFERER, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201');
$result = curl_exec($curl);
curl_close($curl);
preg_match_all('@<p class="wa-rank-list__value"><small>#</small>(.*?)</p>@si',$result,$r);
echo $r[1][1];
?>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading