Extract script contents

1

Good evening. How can I extract the value of "csrf_token" from this code on the page:

EDIT: A "}" was missing at the end of string of%% of%, so the json string was invalid.

<script type="text/javascript">window._sharedData = {"activity_counts":null,"config":{"csrf_token":"WrNBfRGzWkUl4tsZsqm1HfwhDUDKNFts","viewer":null},"supports_es6":true,"country_code":"unknown","language_code":"pt-br","locale":"pt_BR","entry_data":{"LoginAndSignupPage":[{"captcha":{"enabled":false,"key":""},"gdpr_required":false,"tos_version":"row","username_hint":""}]},"gatekeepers":{"ld":true,"seo":true,"seoht":true,"sf":true,"saa":true},"knobs":{"acct:ntb":0,"cb":0,"captcha":0}}

I tried this way, but I did not succeed:

$data = curl_exec($ch);
          $json = json_decode($data, true);
          echo  $json["config"][0]["csrf_token"];
    
asked by anonymous 24.07.2018 / 00:38

1 answer

0
<?php
// passando o json diretamente para poder testar
$data = '{"activity_counts":null,"config":{"csrf_token":"WrNBfRGzWkUl4tsZsqm1HfwhDUDKNFts","viewer":null},"supports_es6":true,"country_code":"unknown","language_code":"pt-br","locale":"pt_BR","entry_data":{"LoginAndSignupPage":[{"captcha":{"enabled":false,"key":""},"gdpr_required":false,"tos_version":"row","username_hint":""}]},"gatekeepers":{"ld":true,"seo":true,"seoht":true,"sf":true,"saa":true},"knobs":{"acct:ntb":0,"cb":0,"captcha":0}}';

$json = json_decode($data); // transformando string json em objeto

// acessando atributo da chave desejada
var_dump($json->{'config'}->{'csrf_token'});
?>

I hope I have helped you.

    
24.07.2018 / 00:59