2015-08-14 101 views
1

我動態生成的URL與PHP簡單的HTML DOM來解析,但該頁面引導到使用Javascript其他動態greated URL,下面是它重定向解析用PHP簡單的HTML DOM重定向頁面

<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將腳本從腳本中取出。

我覺得我現在在Inception

在此先感謝!

這裏我的劇本是

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

我很困惑。如果像你說的那樣,你的腳本加載並執行基於JavaScript的重定向並出現在目標位置(但是你做到了這一點),那麼你的問題是什麼?那不是_exactly_你想要什麼? – arkascha

+0

你在哪裏/如何動態生成此網址?如果你正在構建整個''塊,那麼大概你已經將url分開了。 –

+0

不,我希望它能夠解析重定向頁面,然後呼應的元素解析不僅僅是加載頁面 –

回答

0

所以,你只是想拉出該網址與正則表達式?這應該看起來像這樣:

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