我正在动态生成一个用PHP简单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。
我觉得我现在正处于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 :(得分:0)
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);
}