目录

纯粹的Node.js中的谷歌地图抓取功能

良好的计算机编程知识水平、浏览器模拟、代理和reCAPTCHA解算器对于提取谷歌地图非常重要。同样,你必须准备好应对谷歌可能对其自适应内容做出的任何改变。

为了有效地采用浏览器模拟,你首先需要模拟实际用户的行为。使用  或其他浏览器仿真器可能是一个可行的选择。

然后,你将需要利用 代理人 在第二位,如果你想保护你的工作场所或私人住宅的IP地址。正因为如此,你将能够从其他用户的IP地址请求网站。

你不希望你的IP在reCAPTCHA发生时被切换,因此你可以添加一个 reCAPTCHA解算器 到你的系统,因为尽管有这些工具收集,谷歌仍然可能显示reCAPTCHA,并将其连接到你的一些IP。即使你有一个很好的流量,这也可能发生。

此外,有些时候,谷歌可能真的会改变它提供的信息。简单的日常测试就能完成工作。

将一个搜刮器付诸实施可能是一个广泛的过程,但它最终是可以完成和发展的。关于使用Python和Selenium刮取谷歌地图的进一步信息,请看这个详细的指南。 How to Scrape Google Maps with Python and Selenium.

用Outscraper Node.js包抓取谷歌地图

使用 Outscraper Node.js库 将提高搜刮谷歌地图的质量。它提供了方便的访问 Outscraper API 从用Node.js语言编写的应用程序,允许你使用 Outscraper的服务 从你的代码中。

你可以先安装 该包裹 并在以下网站创建一个账户 Outscraper.

安装

通过运行以下命令安装Outscraper SDK。

				
					npm install outscraper --save
# Or
yarn add outscraper
				
			

初始化

通过导入类和添加你的秘密API密钥来初始化Outscraper客户端。你可以在以下网站上生成API密钥 个人资料页面.

				
					const Outscraper = require('outscraper');
// Or using ES modules:
import Outscraper from 'outscraper';

let client = new Outscraper('SECRET_API_KEY');
				
			

使用实例

以下是如何通过使用搜索查询从谷歌地图上搜刮地方的例子。

				
					// Search for businesses in specific locations:
client.googleMapsSearchV2(['restaurants brooklyn usa'], limit=20, language='en', region='us').then(response => {
  console.log(response);
});


// Scrap Places by Two Queries
client.googleMapsSearchV2(
  ['restaurants brooklyn usa', 'bars brooklyn usa'],
  limit=50, // limit of palces per each query
  language='en',
  region='US',
).then(response => {
  response.forEach(queryPlaces => {
    queryPlaces.forEach(place => {
      console.log('--------------------');
      console.log('query: ', place.query);
      console.log('name: ', place.name);
      console.log('phone: ', place.phone);
      console.log('site: ', place.site);
    });
  });
});
				
			

也可以通过使用地点标识来提取数据。

				
					// Get data of the specific place by id
client.googleMapsSearchV2(['ChIJrc9T9fpYwokRdvjYRHT8nI4'], language='en').then(response => {
  console.log(response);
});

// Scrap Places by Place Ids
client.googleMapsSearchV2(
  ["ChIJ8ccnM7dbwokRy-pTMsdgvS4", "ChIJN5X_gWdZwokRck9rk2guJ1M", "ChIJxWLy8DlawokR1jvfXUPSTUE"],
  limit=1, // limit of palces per each query
).then(response => {
  response.forEach(queryPlaces => {
    queryPlaces.forEach(place => {
      console.log('--------------------');
      console.log('name: ', place.name);
      console.log('place_id: ', place.place_id);
    });
  });
});
				
			

现在就试试Outscraper SDK

Outscraper SDK已经使它变得简单,并为你提供了一个有效的方法,可以轻松地用Node.js做谷歌地图的刮削。只需注册就可以试用我们的免费层。

常见问题

最常见的问题和答案

你可以通过使用Outscraper SDK刮取谷歌地图结果。指定搜索查询、语言和其他参数,并发送您的请求。
npm install outscraper --save
# 或者
yarn add outscraper
const Outscraper = require('outscraper');
// 或者使用ES模块。
从'outscraper'导入Outscraper。

let client = new Outscraper('SECRET_API_KEY');
// 搜索特定地点的企业。
client.googleMapsSearchV2(['restables brooklyn usa'], limit=20, language='en', region='us').then(response => {
  console.log(response);
});


// 通过两个查询来抓取地方
client.googleMapsSearchV2(
  ['restraurants brooklyn usa', 'bar brooklyn usa'],
  limit=50, //每个查询的地点数量限制
  language='en',
  region='US',
).then(response => {
  response.forEach(queryPlaces => {
    queryPlaces.forEach(place => {
      console.log('--------------------');
      console.log('query: ', place.query);
      console.log('name: ', place.name);
      console.log('phone: ', place.phone);
      console.log('site: ', place.site);
    });
  });
});

刮取谷歌地图需要良好的编码知识、浏览器模拟、代理和 reCAPTCHA解算器。 此外,你也应该准备好应对谷歌可能对其动态内容做出的改变。

谷歌地图不允许搜刮。虽然,搜刮和提取公共数据是受美国宪法第一修正案保护的。

类别: API

尤努斯

市场营销人员、内容写作人员、客户体验开发人员----。 Facebook | 领英 | 推特

0 评论

发表回复

头像占位符