thankusomuch
Goto Top

How to get counter value from ebay

hi there.
I am desperatly trying to get the counter value from ebay-kleinanzeigen but it cant get it working.
Any Idea?

<html>
 <head>
  <title>Counter value</title>
 </head>
 <body>
 
 <?php 

$url = "https://www.ebay-kleinanzeigen.de/s-615080998/k0";   
$content = file_get_contents($url);
$first_step = explode( '<div id="viewad-cntr" class="textcounter">' , $content );  
$second_step = explode("</div>" , $first_step[1] );  

echo $second_step;

 ?>
 </body>
</html>

the output is:
<span id="viewad-cntr-num"></span>  

but there is the value missing?
for example :
<span id="viewad-cntr-num">00004</span>  
How can I get it?
thanks you in advance.

Content-Key: 331880

Url: https://administrator.de/contentid/331880

Printed on: April 19, 2024 at 10:04 o'clock

Mitglied: 132658
132658 Mar 11, 2017 updated at 11:02:10 (UTC)
Goto Top
Hi there,
that's because the counter-value ist set dynamically by JavaScript. That's the reason why you don't get any value, file_get_contents only gets static content and doesn't trigger page events face-wink.

Regards
schnappi
Member: colinardo
Solution colinardo Mar 11, 2017 updated at 11:11:44 (UTC)
Goto Top
Hi @thankusomuch,
like @132658 wrote, this information is set by javascript and fetched via an ajax request from another page with a json result in which you can find the data. So it's very easy to extract the page visits with this code:
<?php
	$artikelnr = "615080998";   
	$contents = file_get_contents("https://www.ebay-kleinanzeigen.de/s-vac-inc-get.json?adId=".$artikelnr);  
	$json = json_decode($contents);
	echo "Visits: " . $json->numVisits;  
?>
Best regards
Uwe
Member: thankusomuch
thankusomuch Mar 11, 2017 at 11:23:14 (UTC)
Goto Top
You are amazing!!!
Thanks a lot !!!!
Member: thankusomuch
thankusomuch Mar 11, 2017 at 11:37:05 (UTC)
Goto Top
As you are a genius and i am still a beginner i hope you can help me out with this one too?

How can I respond to the result?
I trying to find the answer online but no way face-sad

so if the answer is 0 ----> echo first visitor
else ----> echo you are not the first .

Hope its okay to ask here without opening a new topic.

once again thank you all
Member: colinardo
Solution colinardo Mar 11, 2017 updated at 11:42:26 (UTC)
Goto Top
if ($json->numVisits == 0){
   echo "first visitor";  
}else{
   echo "you are not the first";  
}
http://php.net/manual/de/control-structures.if.php
Member: thankusomuch
thankusomuch Mar 11, 2017 at 11:43:29 (UTC)
Goto Top
you are definitely a genius!!!
you cant imagine since how long I were looking for this answer online. face-smile
thanks