php - simple-html-dom::restore_noise to parse an on-page javascript
Get the solution ↓↓↓I am trying to parse some a javascript on this page: http://www.chrystals.co.im/residential/Ramsey/House/Gardeners-Lane-Ramsey1117/view-map/1117
However, when parsing the dom, simple_html_dom removes what it considers noise and hence does not allow me to get the inner text of the script tags.
There seems to be a function to restore this noise, although it is not documented, called restore_noise.
It doesn't seem to have any effect. I have tried restoring the noise on the whole page:
$mappage = simple_html_dom::restore_noise($mappage);
and in the parsing loop:
$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;
}
Any ideas? Thanks.
Answer
Solution:
Gave up with the simple_html_dom approach in the end and just used some old fashioned 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];
}
}
Not being a great regex specialist, I found this site which helped me enormously:
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: call to a member function getclientoriginalname() on null
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.