本案例由于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";

程序的主要思路是将整个中国的范围包含在我们设置的区域里。 之后就程序自动拖动获取小区信息。 在抓去详细信息。

  1. private void GetAraeInfo(string araeCode)
  2. {
  3. int zoom = ;
  4. var objPar = new object[];
  5. objPar[] = this.currentPointF.X;
  6. objPar[] = this.currentPointF.Y;
  7. objPar[] = zoom;
  8. wbGoogle.Document.InvokeScript("SetCenter", objPar);
  9. var latlngArr = wbGoogle.Document.InvokeScript("GetBounds").ToString().Split(',');
  10. this.subX = double.Parse(latlngArr[]) - double.Parse(latlngArr[]);
  11. this.subY = double.Parse(latlngArr[]) - double.Parse(latlngArr[]);
  12. string url = string.Format(areaStr, latlngArr[], latlngArr[], latlngArr[], latlngArr[]);
  13. GetInfo(url, araeCode);
  14. bool flag = false;
  15. while (true)
  16. {
  17. if (this.currentPointF.X > this.rightBottomPointF.X)
  18. {
  19. this.currentPointF.X = this.currentPointF.X - this.subX;
  20. }
  21. else
  22. {
  23. if (flag)
  24. {
  25. break;
  26. }
  27. this.currentPointF.Y = this.currentPointF.Y + this.subY;
  28. this.currentPointF.X = this.leftTopPointF.X;
  29. if (this.currentPointF.Y > this.rightBottomPointF.Y)
  30. {
  31. flag = true;
  32. }
  33. }
  34. //地图设置中心点
  35. objPar[] = this.currentPointF.X;
  36. objPar[] = this.currentPointF.Y;
  37. objPar[] = zoom;
  38. Console.WriteLine("X:" + this.currentPointF.X + " Y:" + this.currentPointF.Y);
  39. wbGoogle.Document.InvokeScript("SetCenter", objPar);
  40. latlngArr = wbGoogle.Document.InvokeScript("GetBounds").ToString().Split(',');
  41. url = string.Format(areaStr, latlngArr[], latlngArr[], latlngArr[], latlngArr[]);
  42. GetInfo(url, araeCode);
  43. Thread.Sleep();
  44. Application.DoEvents();
  45. }
  46. }

获取html数据信息当然也是少不了的。

  1. public static String GetHtml(string url)
  2. {
  3. try
  4. {
  5.  
  6. HttpWebRequest req = HttpWebRequest.Create(url) as HttpWebRequest;
  7. req.Timeout = * ;
  8. req.Method = "get";
  9. req.ContentType = "application/x-www-form-urlencoded";
  10. req.Accept = "*/*";
  11. req.Headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN");
  12. 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)";
  13. HttpWebResponse response = req.GetResponse() as HttpWebResponse;
  14. Stream stream = response.GetResponseStream();
  15. MemoryStream buffer = new MemoryStream();
  16. Byte[] temp = new Byte[];
  17. int count = ;
  18. while ((count = stream.Read(temp, , )) > )
  19. {
  20. buffer.Write(temp, , count);
  21. }
  22.  
  23. return System.Text.Encoding.GetEncoding("utf-8").GetString(buffer.GetBuffer());//.UTF8.GetString();
  24. }
  25. catch
  26. {
  27. return String.Empty;
  28. }
  29. }
  1. private void GetInfo(string url, string araeCode)
  2. {
  3.  
  4. string html = GetHtml(url);
  5. if (string.IsNullOrWhiteSpace(html))
  6. return;
  7. html = html.Substring(, html.Length - );
  8. int index = html.IndexOf("]}");
  9. var javascript = new JavaScriptSerializer();
  10. html = html.Substring(, index);//},{
  11. var a = html.Split(',');
  12. List<area> areaLst = new List<area>();
  13. for (int i = ; i < a.Length; i = i + )
  14. {
  15. area area = new area();
  16. area.id = a[i].Substring(, a[i].Length - );
  17. area.zrange = a[i + ] + a[i + ];
  18. area.layer = a[i + ];
  19. area.epoch = a[i + ];
  20. areaLst.Add(area);
  21. }
  22. foreach (var item in areaLst)
  23. {
  24. string tmpurl = string.Format(areaInfoStr, item.id);
  25. string insertHtml = GetHtml(tmpurl);
  26. string tmp = insertHtml;
  27. string baseStr = string.Empty;
  28. int indexTitle = tmp.IndexOf("base:");
  29. if (indexTitle != -)
  30. {
  31. tmp = tmp.Substring(indexTitle + , tmp.Length - indexTitle - );
  32. indexTitle = tmp.IndexOf("]");
  33. if (indexTitle != -)
  34. {
  35. baseStr = tmp.Substring(, indexTitle);
  36. tmp = tmp.Substring(indexTitle, tmp.Length - indexTitle);
  37. }
  38. }
  39. List<AreaInfo> strLst = new List<AreaInfo>();
  40. while (true)
  41. {
  42. AreaInfo areaInfo = new AreaInfo();
  43. areaInfo.Offset = baseStr;
  44. areaInfo.AreaCode = araeCode;//行政区划码
  45. areaInfo.ID = Guid.NewGuid();
  46. string aStr = string.Empty;
  47. indexTitle = tmp.IndexOf("a:");
  48. if (indexTitle != -)
  49. {
  50. tmp = tmp.Substring(indexTitle + , tmp.Length - indexTitle - );
  51. indexTitle = tmp.IndexOf("]");
  52. if (indexTitle != -)
  53. {
  54. aStr = tmp.Substring(, indexTitle);
  55. areaInfo.InnerOffset = aStr;
  56. tmp = tmp.Substring(indexTitle, tmp.Length - indexTitle);
  57. }
  58. }
  59.  
  60. indexTitle = tmp.IndexOf("title:");
  61. if (indexTitle != -)
  62. {
  63. tmp = tmp.Substring(indexTitle + , tmp.Length - indexTitle - );
  64. //获取小区信息
  65. indexTitle = tmp.IndexOf(",");
  66. if (indexTitle != -)
  67. {
  68. string araeName = tmp.Substring(, indexTitle).Replace("\\", "").Replace("\"", "");
  69. areaInfo.Name = araeName;
  70. if (!strLst.Exists(p => p.Name == araeName))
  71. {
  72. strLst.Add(areaInfo);
  73. //lsvAreaInfo.Items.Add(araeName);
  74. }
  75. tmp = tmp.Substring(indexTitle, tmp.Length - indexTitle);
  76. }
  77. }
  78. else
  79. {
  80. break;
  81. }
  82. Thread.Sleep();
  83. Application.DoEvents();
  84. }
  85.  
  86. Application.DoEvents();
  87. Thread.Sleep();
  88.  
  89. }
  90. }

至此我们就可以通过代码来获取google地图中你需要获取的信息。 此案例为获取全国小区信息。 当然我们需要获取其他查询的信息也是可行的。 具体的数据分析我并没用测试。但是原理应该是一样的。希望对你有帮助。

当然我的这个抓去时间主要是由于google的单用户访问次数有关。 可以购买相关的google产品获取想要的数据。

根据google地图抓去全国信息- 抓去全国小区以及新建楼盘信息的更多相关文章

  1. Google地图路线规划

    Google地图路线规划: 需求:给定的两点之间Google地图路径规划和详情. 代码实现: //map定义省略 var directionsDisplay = new google.maps.Dir ...

  2. Google 地图 API V3 使用入门

    Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...

  3. Google 地图 API V3 针对移动设备进行开发

    Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...

  4. Google 地图 API V3 之事件

    Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...

  5. Google 地图 API V3 之控件

    Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...

  6. Google 地图 API V3 之 叠加层

    Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...

  7. Flex加载google地图、百度地图以及天地图作底图

    一  Flex加载Google地图作底图 (1)帮助类GoogleLayer.as /* * 根据输入的地图类型加载Google地图(by chenyuming) */ package Layers ...

  8. 20+ 个很有用的 jQuery 的 Google 地图插件

    转自:http://www.oschina.net/translate/20-useful-jquery-google-maps-plugins Google 地图在寻找我们想要了解的商店或者其它有趣 ...

  9. Google地图接口API之Google地图 API 参考手册(七)

    Google 地图API 参考手册 地图 构造函数/对象 描述 Map() 在指定的 HTML 容器中创建新的地图,该容器通常是一个DIV元素. 叠加层 构造函数/对象 描述 Marker 创建一个标 ...

随机推荐

  1. hbase-0.94 Java API

    Hierarchy For Package org.apache.hadoop.hbase Package Hierarchies: All Packages Class Hierarchy java ...

  2. java异常

    java之异常 认识java中的异常: 有过编程经历的人都会知道,出错在编写程序时,是再正常不过的事,当运行程序时,每次看到那个程序出错时,都会觉得心塞,但是最让人心塞的事情往往是——程序运行的结果和 ...

  3. java中Integer,String判断相等与integer的比较大小

    package sfk.bbs.test.springjsbctempletTest; import static org.junit.Assert.*; import org.junit.Test; ...

  4. U盘启动盘的制作--用U盘硬装Windows系统、或是重装Windows系统

    借助IT天空的优启通U盘启动盘的制作--用U盘装Windows系统.或是重装Windows系统之U盘启动盘的制作 1.==================================== 2.== ...

  5. 探索ASP.NET MVC框架之控制器的查找与激活机制

    引言 前面一篇博文我们介绍了MVC框架的路由机制,我们知道一个URL请求如何从ASP.NET处理管线到达了IHttpHandler实例(MvcHandler).今天我们从MvcHandler来进行下一 ...

  6. golang笔记——array

    1.定义一个 array 数组长度也是类型的一部分,比如长度为3的int数组与长度为5的int数组,并不是同一类型. package main import ( "strconv" ...

  7. 大熊君学习html5系列之------requestAnimationFrame(实现动画的另一种方案)

    一,开篇分析 Hi,大家好!大熊君又和大家见面了,(*^__^*) 嘻嘻……,这系列文章主要是学习Html5相关的知识点,以学习API知识点为入口,由浅入深的引入实例, 让大家一步一步的体会" ...

  8. codevs3250 操作序列

    题目描述 Description Petya是一个非常好玩孩子.他很无聊,因此他开始玩下面的游戏: 他得到一个长度为N的整数序列,他会对这些数字进行操作,他可以把某个数的数值加1或者减1(当然他可以对 ...

  9. nyoj220 推桌子(贪心算法)

    这道题太坑了,from 和to有可能写反,还得正过来: 推桌子 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 The famous ACM (Advanced Co ...

  10. Fold Change和t分布

    基因表达谱数据 基因表达谱可以用一个矩阵来表示,每一行代表一个基因,每一列代表一个样本(如图1).所有基因的表达谱数据在“gene_exp.txt”文件中存储,第一列为基因的entrez geneid ...