スクレイピングされた HTML の経度と緯度に一致する正規表現がどこで間違っているかわかりますか?
スクリプトは、file_get_contents を使用して HTML をロードし、正規表現と preg_match を使用して緯度と経度を抽出することで機能するはずです。現在、以下のスクリプトは緯度と経度の両方で空白を出力しています。何が問題なのかよくわかりません。正規表現は私にとってあまり得意ではありません。ありがとう。
$url = 'http://www.homebase.co.uk/webapp/wcs/stores/servlet/StoreLocatorFlow?slsid=658';
$scrapedPage = file_get_contents($url);
返された html には、次のような行があります。
<p class="geo"> <abbr class="latitude" title="52.19166">52.19166</abbr> <abbr class="longitude" title="-2.23108">-2.23108</abbr> </p>
次に、preg_match を実行します。
preg_match('/class="latitude"\s*title="([^"]+)"/', $scrapedPage, $lat);
preg_match('/class="longitude"\s*title="([^"]+)"/', $scrapedPage, $lon);
echo '<latitude>'.$lat[1].'</latitude>';
echo '<longitude>'.$lon[1].'</longitude>';