-1

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

Please give me a help.

Irene Lorkos
  • 41
  • 1
  • 7

1 Answers1

1
<?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];
?>
  • or find('div.wa-rank-list__value change find('p.wa-rank-list__value – ulusanyazilim Jan 30 '22 at 23:47
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the [help center](https://stackoverflow.com/help/how-to-answer). – Ethan Jun 26 '22 at 16:47