首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >simple-html-dom::restore_noise解析页面上的javascript

simple-html-dom::restore_noise解析页面上的javascript
EN

Stack Overflow用户
提问于 2013-12-06 18:26:48
回答 1查看 222关注 0票数 0

我正在尝试解析这个页面上的一些javascript:http://www.chrystals.co.im/residential/Ramsey/House/Gardeners-Lane-Ramsey1117/view-map/1117

然而,在解析dom时,simple_html_dom删除了它认为是噪声的东西,因此不允许我获得脚本标记的内部文本。

似乎有一个功能可以恢复这种噪音,尽管没有文档记录,称为restore_noise。

它似乎没有任何效果。我试着恢复整个页面的噪音:

代码语言:javascript
复制
$mappage = simple_html_dom::restore_noise($mappage);

在解析循环中:

代码语言:javascript
复制
$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;
                    }

有什么想法吗?谢谢。

EN

回答 1

Stack Overflow用户

发布于 2013-12-10 18:12:49

最后放弃了simple_html_dom方法,只使用了一些老式的preg_matching!

代码语言:javascript
复制
            $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/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20421555

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档