Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用scrapy从这个html中刮取经度和纬度_Python_Scrapy - Fatal编程技术网

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。但我无法得到@非常感谢你。我用你的方法得到了坐标,非常感谢。我用你的方法得到了坐标。