2012-03-25 6 views
0

Ich versuche Data Mining zu betreiben. Ich benutze Xpath versucht, Bilder und Breite und Länge von einer Karte im Browser zu scrappen. Die Bilder sind in einer geschachtelten Tabelle der Weg zu dieser Reihe von Bildern gibt mir ein Problem. Auch die Breite und Länge sind in einem Skript und Ich muss extrahieren, weiß jemand, wie man das macht.Breiten- und Längenverschrottung mit Xpath

Hier ist mein Code für die Bilder

<?php 
    $baseUrl='http://www.hassconsult.co.ke/'; 
    $dom = new DOMDocument(); 
    @$dom->loadHTMLFile('http://www.hassconsult.co.ke/index.php?option=com_content&view=article&id=27&Itemid=74&send=5&ref_no=834/II&google=1'); 
    $xpath = new DOMXPath($dom); 

    foreach($xpath->query("//div[@id='mainbody']/table") as $table) { 
    echo $xpath->query(".//img", $table)->item(0)->getAttribute('src'). "\n"; 
    echo $xpath->query(".//tr[3]/td/a/img", $table)->item(0)->getAttribute('src'). "\n";; 
    } 

    ?> 

here is the table outline as shown using firebug for the images 

    <div id="mainbody"> 
<table width="502" cellspacing="0" cellpadding="0" border="0"> 
<tbody> 
<tr> 
<tr> 
<tr> 
<td valign="top" height="69"> 
<a href="/index.php?option=com_content&view=article&id=27&Itemid=74&send=5&ref_no=834/II&photo_no=1"> 
<img width="50" height="45" border="0" style="border:1px #993300 solid;" alt="logo" src="/images/photos/p569_1.jpg"> 
</a> 
<a href="/index.php?option=com_content&view=article&id=27&Itemid=74&send=5&ref_no=834/II&photo_no=2"> 
<img width="50" height="45" border="0" style="border:1px #993300 solid;" alt="logo" src="/images/photos/p569_2.jpg"> 
</a> 
<a href="/index.php?option=com_content&view=article&id=27&Itemid=74&send=5&ref_no=834/II&photo_no=3"> 
<img width="50" height="45" border="0" style="border:1px #993300 solid;" alt="logo" src="/images/photos/p569_3.jpg"> 
</a> 
<a href="/index.php?option=com_content&view=article&id=27&Itemid=74&send=5&ref_no=834/II&photo_no=4"> 
<img width="50" height="45" border="0" style="border:1px #993300 solid;" alt="logo" src="/images/photos/p569_4.jpg"> 
</a> 
<a href="/index.php?option=com_content&view=article&id=27&Itemid=74&send=5&ref_no=834/II&photo_no=5"> 
<img width="50" height="45" border="0" style="border:1px #993300 solid;" alt="logo" src="/images/photos/p569_5.jpg"> 
</a> 
<a href="/index.php?option=com_content&view=article&id=27&Itemid=74&send=5&ref_no=834/II&photo_no=6"> 
<img width="50" height="45" border="0" style="border:1px #993300 solid;" alt="logo" src="/images/photos/p569_6.jpg"> 
</a> 
<a href="/index.php?option=com_content&view=article&id=27&Itemid=74&send=5&ref_no=834/II&photo_no=7"> 
<img width="50" height="45" border="0" style="border:1px #993300 solid;" alt="logo" src="/images/photos/p569_7.jpg"> 
</a> 
<div style="font-family:Arial, Helvetica, sans-serif;font-size:12px;font-weight:bold;color:#FF9900;padding-top:10px;"></div> 
<strong> 
<br> 
<div style="font-family:Arial, Helvetica, sans-serif;font-size:12px;color:#000000;text-align:justify;"> 
</td> 
</tr> 
<tr> 
<tr> 
</tbody> 
</table> 
</div> 
</div> 

hier ist die Funktion, die die geopoints zeigt, wie Firebug gezeigt

<tr> 
<td> 
<br> 
<br> 
<div id="map_canvas" style="width: 450px; height: 450px; position: relative; background-color: rgb(229, 227, 223);"> 
<script> 
function initialize() { 
if (GBrowserIsCompatible()) { 
var map = new GMap2(document.getElementById("map_canvas")); 
var point = new GLatLng(-1.242831, 36.777805);//how will i pick these values and echo 
map.setCenter(point, 16); 
map.addControl(new GLargeMapControl()); 
map.addControl(new GMapTypeControl()); 
map.addControl(new GScaleControl()); 
map.setUIToDefault(); 
map.setMapType(G_NORMAL_MAP); 
var marker = new GMarker(point); 
map.addOverlay(marker); 
GEvent.addListener(marker, "click", function() {marker.openInfoWindowHtml('<h3>Hillview<br /><a href="http://maps.google.com/maps?saddr=&daddr=' + point.toUrlValue() + '" target ="_blank">Get Directions<\/a>');}); 
} 
} 
window.onload = initialize; 
window.onunload = GUnload; 
</script> 
</td> 
</tr> 

Antwort

0

Sie können XPath verwenden, um die Skriptinhalte zu bekommen, aber Sie müssen (idealerweise ein js-Parser) oder regex, um diese Werte zu erhalten:

$src = $xpath->query("//script")->item(0)->nodeValue; 
preg_match('/GLatLng\(([\d.-]+), ([\d.-]+)\)/', $src, $m); 
list(, $lat, $lng) = $m; 
+0

Danke, das funktioniert :) – user1207576