我正在动态生成一个url,要用PHP简单的HTML DOM解析,但该页面使用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;
}
你只是想用正则表达式把url拉出来吗?它应该看起来像这样:
$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);
}