我正在尝试解析这个页面上的一些javascript:http://www.chrystals.co.im/residential/Ramsey/House/Gardeners-Lane-Ramsey1117/view-map/1117
然而,在解析dom时,simple_html_dom删除了它认为是噪声的东西,因此不允许我获得脚本标记的内部文本。
似乎有一个功能可以恢复这种噪音,尽管没有文档记录,称为restore_noise。
它似乎没有任何效果。我试着恢复整个页面的噪音:
$mappage = simple_html_dom::restore_noise($mappage);在解析循环中:
$url = http://www.chrystals.co.im/residential/Ramsey/House/Gardeners-Lane-Ramsey1117/view-map/1117
$mappage = file_get_html($url);
foreach($mappage->find('script[!src]') as $s) {
$s = simple_html_dom::restore_noise($s);
$x = $s->plaintext;
}有什么想法吗?谢谢。
发布于 2013-12-10 18:12:49
最后放弃了simple_html_dom方法,只使用了一些老式的preg_matching!
$viewoptions = $detail->find('h4.view-options',0);
foreach($viewoptions->find('a') as $element) {
if(preg_match('/view-map/', $element->href)){
$mapurl = $baseurl.$element->href;
$item['mapurl'] = $mapurl;
$mappage = file_get_contents($mapurl);
$pattern = '/_geocoder_addMarker\(.*[0-9]\.[0-9]*/';
preg_match($pattern, $mappage, $matches);
$pattern = '/_geocoder_addMarker\(/';
$latlng = preg_replace($pattern,"" ,$matches[0]);
$latlng = explode(",", $latlng);
$item['lat'] = $latlng[0];
$item['lng'] = $latlng[1];
}
}我不是一个优秀的正则表达式专家,我发现这个网站对我有很大的帮助:
http://www.phpliveregex.com/
https://stackoverflow.com/questions/20421555
复制相似问题