最新想用爬虫实现抓取五大门户网站(搜狐、新浪、网易、腾讯、凤凰网)和电商数据(天猫,京东,聚美等), 今天第一天先搭建下环境和测试。

采用maven+xpath+ HttpClient+正则表达式。

maven pom.xml配置文件信息

  1. <dependency>
  2. <groupId>junit</groupId>
  3. <artifactId>junit</artifactId>
  4. <version>4.12</version>
  5. <scope>test</scope>
  6. </dependency>
  7. <dependency>
  8. <groupId>org.apache.spark</groupId>
  9. <artifactId>spark-core_2.10</artifactId>
  10. <version>1.6.0</version>
  11. </dependency>
  12. <dependency>
  13. <groupId>org.apache.spark</groupId>
  14. <artifactId>spark-sql_2.10</artifactId>
  15. <version>1.6.0</version>
  16. </dependency>
  17. <dependency>
  18. <groupId>org.apache.spark</groupId>
  19. <artifactId>spark-hive_2.10</artifactId>
  20. <version>1.6.0</version>
  21. </dependency>
  22. <dependency>
  23. <groupId>org.apache.spark</groupId>
  24. <artifactId>spark-streaming_2.10</artifactId>
  25. <version>1.6.0</version>
  26. </dependency>
  27. <dependency>
  28. <groupId>org.apache.hadoop</groupId>
  29. <artifactId>hadoop-client</artifactId>
  30. <version>2.6.0</version>
  31. </dependency>
  32. <dependency>
  33. <groupId>org.apache.spark</groupId>
  34. <artifactId>spark-streaming-kafka_2.10</artifactId>
  35. <version>1.6.0</version>
  36. </dependency>
  37. <dependency>
  38. <groupId>org.apache.spark</groupId>
  39. <artifactId>spark-graphx_2.10</artifactId>
  40. <version>1.6.0</version>
  41. </dependency>
  42. <!-- httpclient4.4 -->
  43. <dependency>
  44. <groupId>org.apache.httpcomponents</groupId>
  45. <artifactId>httpclient</artifactId>
  46. <version>4.4</version>
  47. </dependency>
  48. <!-- htmlcleaner -->
  49. <dependency>
  50. <groupId>net.sourceforge.htmlcleaner</groupId>
  51. <artifactId>htmlcleaner</artifactId>
  52. <version>2.10</version>
  53. </dependency>
  54. <!-- json -->
  55. <dependency>
  56. <groupId>org.json</groupId>
  57. <artifactId>json</artifactId>
  58. <version>20140107</version>
  59. </dependency>
  60.  
  61. <!-- hbase -->
  62. <dependency>
  63. <groupId>org.apache.hbase</groupId>
  64. <artifactId>hbase-client</artifactId>
  65. <version>0.96.1.1-hadoop2</version>
  66. </dependency>
  67.  
  68. <dependency>
  69. <groupId>org.apache.hbase</groupId>
  70. <artifactId>hbase-server</artifactId>
  71. <version>0.96.1.1-hadoop2</version>
  72. </dependency>
  73.  
  74. <!-- redis 2.7.0-->
  75. <dependency>
  76. <groupId>redis.clients</groupId>
  77. <artifactId>jedis</artifactId>
  78. <version>2.7.0</version>
  79. </dependency>
  80.  
  81. <!-- slf4j -->
  82. <dependency>
  83. <groupId>org.slf4j</groupId>
  84. <artifactId>slf4j-api</artifactId>
  85. <version>1.7.10</version>
  86. </dependency>
  87. <dependency>
  88. <groupId>org.slf4j</groupId>
  89. <artifactId>slf4j-log4j12</artifactId>
  90. <version>1.7.10</version>
  91. </dependency>
  92. <!-- quartz1.8.4 -->
  93. <dependency>
  94. <groupId>org.quartz-scheduler</groupId>
  95. <artifactId>quartz</artifactId>
  96. <version>1.8.4</version>
  97. </dependency>
  98. <!-- curator -->
  99. <dependency>
  100. <groupId>org.apache.curator</groupId>
  101. <artifactId>curator-framework</artifactId>
  102. <version>2.7.1</version>
  103. </dependency>

新建一个测试类:SpiderTest

  1. /**
  2. * url 入口,下载页面
  3. * @param url
  4. */
  5. public static String downLoadCrawlurl(String url){
  6. String context = null;
  7. Logger logger = LoggerFactory.getLogger(SpiderTest.class);
  8. HttpClientBuilder create = HttpClientBuilder.create();
  9. HttpGet httpGet = new HttpGet(url);
  10. CloseableHttpClient build = create.build();
  11. try {
  12. CloseableHttpResponse response = build.execute( httpGet);
  13. HttpEntity entity = response.getEntity();
  14. context = EntityUtils.toString( entity );
  15. System.out.println("context:" + context);
  16. }
  17. catch ( ClientProtocolException e ) {
  18. e.printStackTrace();
  19. }
  20. catch ( IOException e ) {
  21. logger.info("download...." );
  22. }
  23. return context;
  24. }
  1.  
  1. public static void main( String[] args ) {
  2.   
    String url = "http://money.163.com/";
    downLoadCrawlurl(url);

  3. }

爬虫抓取5大门户网站和电商数据day1:基础环境搭建的更多相关文章

  1. PID控制器的应用:控制网络爬虫抓取速度

    一.初识PID控制器 冬天乡下人喜欢烤火取暖,常见的情形就是四人围着麻将桌,桌底放一盆碳火.有人觉得火不够大,那加点木炭吧,还不够,再加点.片刻之后,又觉得火太大,脚都快被烤熟了,那就取出一些木碳…… ...

  2. 爬虫抓取页面数据原理(php爬虫框架有很多 )

    爬虫抓取页面数据原理(php爬虫框架有很多 ) 一.总结 1.php爬虫框架有很多,包括很多傻瓜式的软件 2.照以前写过java爬虫的例子来看,真的非常简单,就是一个获取网页数据的类或者方法(这里的话 ...

  3. python3.4学习笔记(十四) 网络爬虫实例代码,抓取新浪爱彩双色球开奖数据实例

    python3.4学习笔记(十四) 网络爬虫实例代码,抓取新浪爱彩双色球开奖数据实例 新浪爱彩双色球开奖数据URL:http://zst.aicai.com/ssq/openInfo/ 最终输出结果格 ...

  4. 爬虫技术 -- 进阶学习(七)简单爬虫抓取示例(附c#代码)

    这是我的第一个爬虫代码...算是一份测试版的代码.大牛大神别喷... 通过给定一个初始的地址startPiont然后对网页进行捕捉,然后通过正则表达式对网址进行匹配. List<string&g ...

  5. python 爬虫抓取心得

    quanwei9958 转自 python 爬虫抓取心得分享 urllib.quote('要编码的字符串') 如果你要在url请求里面放入中文,对相应的中文进行编码的话,可以用: urllib.quo ...

  6. 爬虫技术(四)-- 简单爬虫抓取示例(附c#代码)

    这是我的第一个爬虫代码...算是一份测试版的代码.大牛大神别喷... 通过给定一个初始的地址startPiont然后对网页进行捕捉,然后通过正则表达式对网址进行匹配. List<string&g ...

  7. Java 实现 HttpClients+jsoup,Jsoup,htmlunit,Headless Chrome 爬虫抓取数据

    最近整理一下手头上搞过的一些爬虫,有HttpClients+jsoup,Jsoup,htmlunit,HeadlessChrome 一,HttpClients+jsoup,这是第一代比较low,很快就 ...

  8. Python爬虫抓取东方财富网股票数据并实现MySQL数据库存储

    Python爬虫可以说是好玩又好用了.现想利用Python爬取网页股票数据保存到本地csv数据文件中,同时想把股票数据保存到MySQL数据库中.需求有了,剩下的就是实现了. 在开始之前,保证已经安装好 ...

  9. python爬虫抓取哈尔滨天气信息(静态爬虫)

    python 爬虫 爬取哈尔滨天气信息 - http://www.weather.com.cn/weather/101050101.shtml 环境: windows7 python3.4(pip i ...

随机推荐

  1. \r\n\t 转义字符

    https://www.cnblogs.com/lsqbk/p/10259044.html https://www.cnblogs.com/f158w058/p/6548073.html 文件中的换行 ...

  2. 导数与偏导数 Derivative and Partial Derivative

    之前做了很长时间“罗辑思维”的听众,罗胖子曾经讲起过,我们这一代人该如何学习.其中,就讲到我们这个岁数,已经不可能再去从头到尾的学习一门又一门工具课程了,而是在学习某一领域时,有目的的去翻阅工具课程中 ...

  3. python学习笔记:模块——time模块

    timetime模块提供各种时间相关的功能,与时间相关的模块有:time,datetime,calendar等. 时间有三种表示方式,一种是时间戳.一种是格式化时间.一种是时间元组.时间戳和格式化时间 ...

  4. 4154: [Ipsc2015]Generating Synergy

    Description 给定一棵以1为根的有根树,初始所有节点颜色为1,每次将距离节点a不超过l的a的子节点染成c,或询问点a的颜色 区间修改单点查询kdtree #include<iostre ...

  5. 解决Redhat yum出现This system is not registered with RHN的方案

    最近博主在学习Linux,菜鸟级别的的选手连装个Chrome都觉得难,悲了个催的……百度了很多教程,大多是类似的.博主的配置是在VM8下搭建的RHEL5.3 (Tikanga)版本,不知道什么原因,每 ...

  6. pytest_参数化3

    import pytesttest_user_data=[ {'user':'linda','password':'8888'}, {'user':'servenruby','password':'1 ...

  7. 封装加减乘除函数 解决JS 浮点数计算 Bug

    计算机内部的信息都是由二进制方式表示的,即0和1组成的各种编码,但由于某些浮点数没办法用二进制准确的表示出来,也就带来了一系列精度问题.当然这也不是JS独有的问题. 例如, 我们在用JS做浮点运算会遇 ...

  8. LayUI最近遇到的问题以及处理

    layui是我最近才接触的..也是新项目中用到的后台前端框架..与easyui有些类似..在这段时间的使用中,经常会碰到大大小小的问题.. 1.选显卡切换又是加载数据表格.分页条不显示 2.layui ...

  9. js中数据操作的某些思想

    1,默认数据的复用 写成function的return形式缓存在变量中,用的时候直接执行fun就行了 例如 有文件text.js里面的对象是export default ()=>({aa:55, ...

  10. ORM与JPA规范

    一.ORM框架 1.ORM简单介绍 对象关系映射,(Object Relational Mapping,简称ORM),是通过使用描述对象和数据库之间的映射的元数据,将面向对象语言程序中的对象自动持久化 ...