URLからレストランの緯度と経度を削りたいですか?名前、評価などの他の情報は捨てることができますが、ホテルの緯度と経度は除きます。助けて!scrapeを使用してこのhtmlから経度と緯度をこする
私は自分のコードスニペットを添付しています。 image
On inspecting the map on webpage I get this but I am not able to fetch the coordinates from it.
URLからレストランの緯度と経度を削りたいですか?名前、評価などの他の情報は捨てることができますが、ホテルの緯度と経度は除きます。助けて!scrapeを使用してこのhtmlから経度と緯度をこする
私は自分のコードスニペットを添付しています。 image
On inspecting the map on webpage I get this but I am not able to fetch the coordinates from it.
これは、私はあなたのソリューションをしようとしたのxpath
lat = response.xpath('substring-before(normalize-space(substring-after(//script[contains(., "geoId:") and contains(., "lat")]/text(), "lat:")), ",")').extract_first()
lng = response.xpath('substring-before(normalize-space(substring-after(//script[contains(., "geoId:") and contains(., "lng")]/text(), "lng:")), ",")').extract_first()
このような何か:
lat = re.findall(r'lat: (\d+.\d+),', response.text)
lng = re.findall(r'lng: (\d+.\d+),', response.text)
print lat, lng
を使用して別の同様のアプローチです。それはうまくいかなかった。また、response.bodyの代わりにresponse.textを使用します(パターンのような文字列に一致させるためにオブジェクトのようなユーザーバイトはできません)。私は問題があると思う緯度、長いコーディネートはページにあります。私がマップを調べると、imgタグのsrcに長いlatがあります。しかし、私はそれを得ることができません。 @ Verz1Lka –
ありがとうございました。私はあなたの方法を使って座標を得ました。 –