Search code examples
phpfile-get-contentshtml-entities

how to get variable from url that loaded with Java script in php?


i have this URL : http://www.tsetmc.com/Loader.aspx?ParTree=151311&i=65883838195688438

i want to get all numeric data from this website .

e.g : 3.797 M

in this page all data refresh immediately.

i try :

$url = 'http://www.tsetmc.com/Loader.aspx?ParTree=151311&i=65883838195688438';
$data = file_get_contents($url);
echo $html_encoded = htmlentities($data);

or :

$url = 'http://www.tsetmc.com/Loader.aspx?ParTree=151311&i=65883838195688438';
echo $data = file_get_contents($url);

but i cant get numeric data .

both methods does not contain numeric data .


Solution

  • Because the JavaScript generating the page content. All necessary data is in the JavaScript code. Just take a look into page source.

    Piece of code from the source:

    <script type="text/javascript">
    var TradeHistory=[['20170717','2633.00','2577.00','2565.00','2705.00','1679','26095164','68719004798.00'],['20170716','2577.00','2599.00','2550.00','2600.00','840','7655664','19725265524.00'],...
    

    The data comes also from there: IntraDayPrice, instinfofast.aspx