简体   繁体   English

使用php Simple HTML DOM解析重定向页面

[英]Parse a redirect page with php Simple HTML DOM

I am dynamically generating a url to be parsed with PHP Simple HTML DOM but that page directs to another dynamically greated URL using Javascript, below is the script that redirects it 我正在动态生成一个要用PHP Simple HTML DOM解析的URL,但是该页面使用Javascript指向了另一个动态扩展的URL,下面是重定向它的脚本

 <script>window.addEventListener('load', function() { window.location.replace('http://thatsthem.com/search/417-272-0471/7312f62d') });</script> 

So I need a way for the PHP to follow the redirect through to http://thatsthem.com/search/417-272-0471/7312f62d and then parse that page. 因此,我需要一种使PHP遵循重定向到http://thatsthem.com/search/417-272-0471/7312f62d ,然后解析该页面。 But all it does is just load that javascript and then executes it and opens the new page. 但是,它所做的只是加载该javascript,然后执行它并打开新页面。

Or if I can some how extract the URL from the javascript with regex or something and then have my PHP just parse that url, that would work also. 或者,如果我可以一些方法,如何使用正则表达式或其他内容从javascript中提取URL,然后让我的PHP只是解析该URL,那也可以。 But I can't figure out how to get that url out of the script with php. 但是我不知道如何使用php从脚本中获取该url。

I feel like I'm in Inception right now 我觉得我现在正处于盗梦空间

Thanks in advance! 提前致谢!

Here my script is 这是我的剧本

<body>

<form method="post" id="primarysearchfomr">
<input name="number" type="text" value=""/>
<input type="submit" id="searchbutton"/>

</form>

<h1 id="searchform">Search Form</h1>


 <?php
  $searchterm= $_POST["number"];

 $count = null;
  $returnValue = str_replace(array("(",")","-"," "), '', $searchterm,    $count);




   include_once('simple_html_dom.php');
   $target_url = "http://thatsthem.com/searching?ff=true&q0=" . $returnValue;


   $html = new simple_html_dom();
   $html->load_file($target_url);
    foreach($html->find('script',2) as $link)
   {

    echo $link;
    }

So you just want to pull that url out with regex? 因此,您只想使用正则表达式提取该网址? That should look something like: 看起来应该像这样:

$script = "<script>window.addEventListener('load', function() { window.location.replace('http://thatsthem.com/search/417-272-0471/7312f62d') });</script>";

if(preg_match("/'(http.*?)'/", $script, $m)){
  $url = $m[1];
  die($url);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM