簡體   English   中英

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

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

我正在動態生成一個要用PHP Simple HTML DOM解析的URL,但是該頁面使用Javascript指向了另一個動態擴展的URL,下面是重定向它的腳本

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

因此,我需要一種使PHP遵循重定向到http://thatsthem.com/search/417-272-0471/7312f62d ,然后解析該頁面。 但是,它所做的只是加載該javascript,然后執行它並打開新頁面。

或者,如果我可以一些方法,如何使用正則表達式或其他內容從javascript中提取URL,然后讓我的PHP只是解析該URL,那也可以。 但是我不知道如何使用php從腳本中獲取該url。

我覺得我現在正處於盜夢空間

提前致謝!

這是我的劇本

<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;
    }

因此,您只想使用正則表達式提取該網址? 看起來應該像這樣:

$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