Python 使用scrapy从这个html中刮取经度和纬度
我想从地图上看一下这家餐馆的经纬度。我能抓取其他信息,如名称、评级,但不能抓取酒店的纬度和经度。救救我 我正在附加我的代码片段 类似这样的内容:Python 使用scrapy从这个html中刮取经度和纬度,python,scrapy,Python,Scrapy,我想从地图上看一下这家餐馆的经纬度。我能抓取其他信息,如名称、评级,但不能抓取酒店的纬度和经度。救救我 我正在附加我的代码片段 类似这样的内容: lat = re.findall(r'lat: (\d+.\d+),', response.text) lng = re.findall(r'lng: (\d+.\d+),', response.text) print lat, lng 大概是这样的: lat = re.findall(r'lat: (\d+.\d+),', response.tex
lat = re.findall(r'lat: (\d+.\d+),', response.text)
lng = re.findall(r'lng: (\d+.\d+),', response.text)
print lat, lng
大概是这样的:
lat = re.findall(r'lat: (\d+.\d+),', response.text)
lng = re.findall(r'lng: (\d+.\d+),', response.text)
print lat, lng
这是另一种使用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()
这是另一种使用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()
我试过你的解决办法。它不起作用。此外,我们将使用response.text代替response.body(我们不能使用类似字节的对象来匹配类似字符串的模式)。我认为问题在于页面中没有Lat,长时间协调。当我检查地图时,在img标签的src中有lat,long。但我无法得到@Verz1LkaI尝试了你的解决方案。它不起作用。此外,我们将使用response.text代替response.body(我们不能使用类似字节的对象来匹配类似字符串的模式)。我认为问题在于页面中没有Lat,长时间协调。当我检查地图时,在img标签的src中有lat,long。但我无法得到@非常感谢你。我用你的方法得到了坐标,非常感谢。我用你的方法得到了坐标。