Tell me, please, how to parse the js-code from the site? More precisely, I even know a line of code, but how to parse is not.

  • Parse, in the sense of downloading js file and find in it a certain piece of code (text)? - KoVadim
  • @KoVadim to find a certain piece of code in it, or rather its link, there is a line like document.hation = '', then you need to match it in quotes. - Lektor
  • You get content and parsing into variable with regular expressions. $ url = preg_replace ("/.+ document \ .location \ .href = \" (. +?) \ ". + /", "$ 1", $ content); I did not check the code, but something like this. It would be nice to see the exact fragment of js code where the link appears. - Nik555
  • @ Nik555 not working :( - Lektor
  • @Lektor, give the js code snippet so that I can accurately write reg. expression. - Nik555

1 answer 1

<?php $s = file_get_contents("http://"); // ссылка на js файл $m = array(); preg_match_all("/document\.location\.href='(.+?)'/", $s, $m); $url = $m[1][0]; // $url содержит ссылку ?> 
  • @ Nik555 works, thanks! - Lektor