根据google地图抓去全国信息- 抓去全国小区以及新建楼盘信息
本案例由于google每天每个账户能post20000次所以我们需要相对较长的时间来抓去google的数据信息。
主要思路:通过一定的zoom一个相对较大的zoom。我们尽可能的搜索我们的所有数据。 之后我们获取google的搜索数据如下图
我们要抓去的就是上面的小红点了。 我这边抓去全国的小区信息用一台服务器跑了20天左右将全国的小区信息基本上都抓到了。 小到县 镇 的小区信息也抓到了。 相对还是比较理想。当时分析消耗了大量的时间。 由于我需要获取这个小区名称以及地图的坐标点所以这块还是有一定的分析的技术含量的。
抓去的数据不是只有 一个页面我们需要post分页抓去。这点需要注意。代码当时只是比较简单的处理。 注重的是过程就不上传了。 给大家提供一些思路。
我们需要定义2个非常主要的google的url这两个是我们获取地址信息以及经纬度信息的关键点。
private string areaStr = "http://mt0.google.com/vt/pt?lyrs=m%40215000000&las={0}%3B{1}%3B{2}%3B{3}&z=14&ptv=1";
private string areaInfoStr = "http://mt0.google.com/vt/ft?lyrs=lmq:1000:%E5%B0%8F%E5%8C%BA|cc:CN|h:a|s:109146043351405611748|xc:14&las={0}&z=15&gl=cn&hl=zh-CN&xc=1";
程序的主要思路是将整个中国的范围包含在我们设置的区域里。 之后就程序自动拖动获取小区信息。 在抓去详细信息。
private void GetAraeInfo(string araeCode)
{
int zoom = ;
var objPar = new object[];
objPar[] = this.currentPointF.X;
objPar[] = this.currentPointF.Y;
objPar[] = zoom;
wbGoogle.Document.InvokeScript("SetCenter", objPar);
var latlngArr = wbGoogle.Document.InvokeScript("GetBounds").ToString().Split(',');
this.subX = double.Parse(latlngArr[]) - double.Parse(latlngArr[]);
this.subY = double.Parse(latlngArr[]) - double.Parse(latlngArr[]);
string url = string.Format(areaStr, latlngArr[], latlngArr[], latlngArr[], latlngArr[]);
GetInfo(url, araeCode);
bool flag = false;
while (true)
{
if (this.currentPointF.X > this.rightBottomPointF.X)
{
this.currentPointF.X = this.currentPointF.X - this.subX;
}
else
{
if (flag)
{
break;
}
this.currentPointF.Y = this.currentPointF.Y + this.subY;
this.currentPointF.X = this.leftTopPointF.X;
if (this.currentPointF.Y > this.rightBottomPointF.Y)
{
flag = true;
}
}
//地图设置中心点
objPar[] = this.currentPointF.X;
objPar[] = this.currentPointF.Y;
objPar[] = zoom;
Console.WriteLine("X:" + this.currentPointF.X + " Y:" + this.currentPointF.Y);
wbGoogle.Document.InvokeScript("SetCenter", objPar);
latlngArr = wbGoogle.Document.InvokeScript("GetBounds").ToString().Split(',');
url = string.Format(areaStr, latlngArr[], latlngArr[], latlngArr[], latlngArr[]);
GetInfo(url, araeCode);
Thread.Sleep();
Application.DoEvents();
}
}
获取html数据信息当然也是少不了的。
public static String GetHtml(string url)
{
try
{ HttpWebRequest req = HttpWebRequest.Create(url) as HttpWebRequest;
req.Timeout = * ;
req.Method = "get";
req.ContentType = "application/x-www-form-urlencoded";
req.Accept = "*/*";
req.Headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN");
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)";
HttpWebResponse response = req.GetResponse() as HttpWebResponse;
Stream stream = response.GetResponseStream();
MemoryStream buffer = new MemoryStream();
Byte[] temp = new Byte[];
int count = ;
while ((count = stream.Read(temp, , )) > )
{
buffer.Write(temp, , count);
} return System.Text.Encoding.GetEncoding("utf-8").GetString(buffer.GetBuffer());//.UTF8.GetString();
}
catch
{
return String.Empty;
}
}
private void GetInfo(string url, string araeCode)
{ string html = GetHtml(url);
if (string.IsNullOrWhiteSpace(html))
return;
html = html.Substring(, html.Length - );
int index = html.IndexOf("]}");
var javascript = new JavaScriptSerializer();
html = html.Substring(, index);//},{
var a = html.Split(',');
List<area> areaLst = new List<area>();
for (int i = ; i < a.Length; i = i + )
{
area area = new area();
area.id = a[i].Substring(, a[i].Length - );
area.zrange = a[i + ] + a[i + ];
area.layer = a[i + ];
area.epoch = a[i + ];
areaLst.Add(area);
}
foreach (var item in areaLst)
{
string tmpurl = string.Format(areaInfoStr, item.id);
string insertHtml = GetHtml(tmpurl);
string tmp = insertHtml;
string baseStr = string.Empty;
int indexTitle = tmp.IndexOf("base:");
if (indexTitle != -)
{
tmp = tmp.Substring(indexTitle + , tmp.Length - indexTitle - );
indexTitle = tmp.IndexOf("]");
if (indexTitle != -)
{
baseStr = tmp.Substring(, indexTitle);
tmp = tmp.Substring(indexTitle, tmp.Length - indexTitle);
}
}
List<AreaInfo> strLst = new List<AreaInfo>();
while (true)
{
AreaInfo areaInfo = new AreaInfo();
areaInfo.Offset = baseStr;
areaInfo.AreaCode = araeCode;//行政区划码
areaInfo.ID = Guid.NewGuid();
string aStr = string.Empty;
indexTitle = tmp.IndexOf("a:");
if (indexTitle != -)
{
tmp = tmp.Substring(indexTitle + , tmp.Length - indexTitle - );
indexTitle = tmp.IndexOf("]");
if (indexTitle != -)
{
aStr = tmp.Substring(, indexTitle);
areaInfo.InnerOffset = aStr;
tmp = tmp.Substring(indexTitle, tmp.Length - indexTitle);
}
} indexTitle = tmp.IndexOf("title:");
if (indexTitle != -)
{
tmp = tmp.Substring(indexTitle + , tmp.Length - indexTitle - );
//获取小区信息
indexTitle = tmp.IndexOf(",");
if (indexTitle != -)
{
string araeName = tmp.Substring(, indexTitle).Replace("\\", "").Replace("\"", "");
areaInfo.Name = araeName;
if (!strLst.Exists(p => p.Name == araeName))
{
strLst.Add(areaInfo);
//lsvAreaInfo.Items.Add(araeName);
}
tmp = tmp.Substring(indexTitle, tmp.Length - indexTitle);
}
}
else
{
break;
}
Thread.Sleep();
Application.DoEvents();
} Application.DoEvents();
Thread.Sleep(); }
}
至此我们就可以通过代码来获取google地图中你需要获取的信息。 此案例为获取全国小区信息。 当然我们需要获取其他查询的信息也是可行的。 具体的数据分析我并没用测试。但是原理应该是一样的。希望对你有帮助。
当然我的这个抓去时间主要是由于google的单用户访问次数有关。 可以购买相关的google产品获取想要的数据。
根据google地图抓去全国信息- 抓去全国小区以及新建楼盘信息的更多相关文章
- Google地图路线规划
Google地图路线规划: 需求:给定的两点之间Google地图路径规划和详情. 代码实现: //map定义省略 var directionsDisplay = new google.maps.Dir ...
- Google 地图 API V3 使用入门
Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...
- Google 地图 API V3 针对移动设备进行开发
Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...
- Google 地图 API V3 之事件
Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...
- Google 地图 API V3 之控件
Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...
- Google 地图 API V3 之 叠加层
Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...
- Flex加载google地图、百度地图以及天地图作底图
一 Flex加载Google地图作底图 (1)帮助类GoogleLayer.as /* * 根据输入的地图类型加载Google地图(by chenyuming) */ package Layers ...
- 20+ 个很有用的 jQuery 的 Google 地图插件
转自:http://www.oschina.net/translate/20-useful-jquery-google-maps-plugins Google 地图在寻找我们想要了解的商店或者其它有趣 ...
- Google地图接口API之Google地图 API 参考手册(七)
Google 地图API 参考手册 地图 构造函数/对象 描述 Map() 在指定的 HTML 容器中创建新的地图,该容器通常是一个DIV元素. 叠加层 构造函数/对象 描述 Marker 创建一个标 ...
随机推荐
- 使用canvas绘制一片星空
效果图 五角星计算方式 代码 <body style="margin:0px;padding:0px;width:100%;height:100%;overflow:hidden;&q ...
- DevExpress.chartContro控件保存图片和打印图片
private void pictureBox1_Click(object sender, EventArgs e) { ////实例化打印对象 PrintDocument print = new P ...
- bzoj 4318 OSU!
期望dp. 考虑问题的简化版:一个数列有n个数,每位有pi的概率为1,否则为0.求以每一位结尾的全为1的后缀长度的期望. 递推就好了. l1[i]=(l1[i-1]+1)*p[i]+0*(1-p[i] ...
- wpf打开文夹和打开文件
WPF调用WinForm中的 OpenFileDialog 和 FolderBrowserDialog 来实现响应的功能 OpenFileDialog openFileDialog = new Ope ...
- Finite State Machine 是什么?
状态机(Finite State Machine):状态机由状态寄存器和组合逻辑电路构成,能够根据控制信号按照预先设定的状态进行状态转移,是协调相关信号动 作.完成特定操作的控制中心. 类 ...
- Jquery ajax运用执行顺序有误怎么解决
在这儿,可能就要提示一个ajax的一个属性async async默认的设置值为true,这种情况为异步方式,就是说当ajax发送请求后,在等待server端返回的这个过程中,前台会继续执行ajax块后 ...
- Jquery动态添加的元素绑定事件的3种方法
假设我们点击li标签,弹出他的文本,如果是动态添加的li,点击是没有效果的,压根弹不出来文本. 下面博主分享一下为动态添加的元素绑定事件的三种方法,网上一般都是两种,我在这里多增加了一种. 事件案例: ...
- IBatis 2.x 和 MyBatis 3.0.x 的区别(从 iBatis 到 MyBatis)
从 iBatis 到 MyBatis,你准备好了吗? 对于从事 Java EE 的开发人员来说,iBatis 是一个再熟悉不过的持久层框架了,在 Hibernate.JPA 这样的一站式对象 / 关系 ...
- 深入理解javascript原型和闭包(11)——执行上下文栈
继续上文的内容. 执行全局代码时,会产生一个执行上下文环境,每次调用函数都又会产生执行上下文环境.当函数调用完成时,这个上下文环境以及其中的数据都会被消除,再重新回到全局上下文环境.处于活动状态的执行 ...
- 切换数据库+ThreadLocal+AbstractRoutingDataSource 一
最近项目用的数据库要整合成一个,所以把多源数据库切换的写法要清除掉.所以以下记载了多远数据库切换的用法及个人对源码的理解. 框架:Spring+mybatis+vertx,(多源数据库切换的用法不涉及 ...