一.简介:

https://github.com/CrawlScript/WebCollector/blob/master/README.zh-cn.md

二.使用:

 <dependency>
        <groupId>cn.edu.hfut.dmic.webcollector</groupId>
        <artifactId>WebCollector</artifactId>
        <version>2.09</version>
 </dependency>

编码:

import cn.edu.hfut.dmic.webcollector.crawler.BreadthCrawler;
import cn.edu.hfut.dmic.webcollector.model.Links;
import cn.edu.hfut.dmic.webcollector.model.Page;
import java.util.regex.Pattern;
import org.jsoup.nodes.Document;

/**
 * Crawl news from yahoo news
 *
 * @author tom
 */
public class YahooCrawler extends BreadthCrawler {

    /**
     * @param crawlPath crawlPath is the path of the directory which maintains
     * information of this crawler
     * @param autoParse if autoParse is true,BreadthCrawler will auto extract
     * links which match regex rules from pag
     */
    public YahooCrawler(String crawlPath, boolean autoParse) {
        super(crawlPath, autoParse);
        /*start page*/
        this.addSeed("http://news.yahoo.com/");

        /*fetch url like http://news.yahoo.com/xxxxx*/
        this.addRegex("http://news.yahoo.com/.*");
        /*do not fetch url like http://news.yahoo.com/xxxx/xxx)*/
        this.addRegex("-http://news.yahoo.com/.+/.*");
        /*do not fetch jpg|png|gif*/
        this.addRegex("-.*\\.(jpg|png|gif).*");
        /*do not fetch url contains #*/
        this.addRegex("-.*#.*");
    }

    @Override
    public void visit(Page page, Links nextLinks) {
        String url = page.getUrl();
        /*if page is news page*/
        if (Pattern.matches("http://news.yahoo.com/.+html", url)) {
            /*we use jsoup to parse page*/
            Document doc = page.getDoc();

            /*extract title and content of news by css selector*/
            String title = doc.select("h1[class=headline]").first().text();
            String content = doc.select("div[class=body yom-art-content clearfix]").first().text();

            System.out.println("URL:\n" + url);
            System.out.println("title:\n" + title);
            System.out.println("content:\n" + content);

            /*If you want to add urls to crawl,add them to nextLink*/
            /*WebCollector automatically filters links that have been fetched before*/
            /*If autoParse is true and the link you add to nextLinks does not match the regex rules,the link will also been filtered.*/
            // nextLinks.add("http://xxxxxx.com");
        }
    }

    public static void main(String[] args) throws Exception {
        YahooCrawler crawler = new YahooCrawler("crawl", true);
        crawler.setThreads();
        crawler.setTopN();
        //crawler.setResumable(true);
            /*start crawl with depth of 4*/
        crawler.start();
    }

}

搜索引擎爬虫技术研究(爬虫框架)-WebCollector的更多相关文章

  1. Python爬虫技术:爬虫时如何知道是否代理ip伪装成功?

    前言本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. python爬虫时如何知道是否代理ip伪装成功: 有时候我们的爬虫程序添加了 ...

  2. 使用webcollector爬虫技术获取网易云音乐全部歌曲

    最近在知乎上看到一个话题,说使用爬虫技术获取网易云音乐上的歌曲,甚至还包括付费的歌曲,哥瞬间心动了,这年头,好听的流行音乐或者经典老歌都开始收费了,只能听不能下载,着实很郁闷,现在机会来了,于是开始研 ...

  3. golang学习笔记17 爬虫技术路线图,python,java,nodejs,go语言,scrapy主流框架介绍

    golang学习笔记17 爬虫技术路线图,python,java,nodejs,go语言,scrapy主流框架介绍 go语言爬虫框架:gocolly/colly,goquery,colly,chrom ...

  4. .net 爬虫技术

    关于爬虫 从搜索引擎开始,爬虫应该就出现了,爬的对象当然也就是网页URL,在很长一段时间内,爬虫所做的事情就是分析URL.下载WebServer返回的HTML.分析HTML内容.构建HTTP请求的模拟 ...

  5. 爬虫技术 -- 基础学习(四)HtmlParser基本认识

    利用爬虫技术获取网页源代码后,针对网页抽取出它的特定文本内容,利用正则表达式和抽取工具,能够更好地抽取这些内容. 下面介绍一种抽取工具 -- HtmlParser HtmlParser是一个用来解析H ...

  6. 使用htmlparse爬虫技术爬取电影网页的全部下载链接

    昨天,我们利用webcollector爬虫技术爬取了网易云音乐17万多首歌曲,而且还包括付费的在内,如果时间允许的话,可以获取更多的音乐下来,当然,也有小伙伴留言说这样会降低国人的知识产权保护意识,诚 ...

  7. 利用python的爬虫技术爬去糗事百科的段子

    初次学习爬虫技术,在知乎上看了如何爬去糗事百科的段子,于是打算自己也做一个. 实现目标:1,爬取到糗事百科的段子 2,实现每次爬去一个段子,每按一次回车爬取到下一页 技术实现:基于python的实现, ...

  8. 爬虫技术实现空间相册采集器V.0.0.1版本

    一.    功能需求分析: 在很多时候我们需要做这样一个事情:我们想把我们QQ空间上的相册高清图像下载下来,怎么做?到网上找软件?答案是否定的,理由之一:网上很多软件不知有没有病毒,第二它有可能捆了很 ...

  9. 第三百四十二节,Python分布式爬虫打造搜索引擎Scrapy精讲—爬虫数据保存

    第三百四十二节,Python分布式爬虫打造搜索引擎Scrapy精讲—爬虫数据保存 注意:数据保存的操作都是在pipelines.py文件里操作的 将数据保存为json文件 spider是一个信号检测 ...

随机推荐

  1. 前端之css、JavaScript和DOM

    css position 一般组合 relative+absolute,以relative为父元素,absolute依照relative进行定位. opcity: 0.5 透明度 z-index: 层 ...

  2. Python判断当前用户是否是root

    import osif os.geteuid() != 0:print "This program must be run as root. Aborting."sys.exit( ...

  3. hibernate日常BUG总结

    在使用hibernate自动生产表的时候失败, 是配置文件我是从别地方拷贝过来忘记更改,所以报了这个错误. 重新命名了生成表的名称,问题解决! 问题很明显,自动增长的主键应该使用整型. 这里写的是St ...

  4. GitHub访问速度慢的解决方法

    # Github 103.245.222.249 github.global.ssl.fastly.net 103.245.222.133 assets-cdn.github.com 23.235.4 ...

  5. Lua简易入门教程

    环境:lua for windows (lfW)主页:http://luaforwindows.luaforge.net/https://code.google.com/p/luaforwindows ...

  6. 如何准确高效的获取数据库新插入数据的主键id

    例如我们新建了一张表UserInformation,字段如下Id,为主键,自增,其它字段Name,Pwd,Email 然后我们来执行一个新增插入操作: insert into UserInformat ...

  7. Zigzag Iterator

    Given two 1d vectors, implement an iterator to return their elements alternately. For example, given ...

  8. FreeRTOS--删除任务

    FreeRTOS学习笔记——任务删除 vTaskDelete() API - liyan728的专栏 - 博客频道 - CSDN.NET http://blog.csdn.net/liyan728/a ...

  9. XE 的程序升级 XE5 问题处理记录

    XE 的程序升级 XE5 问题处理记录 1.  [dcc32 Fatal Error] frxClass.pas(3556): F1026 File not found: 'xxxxx\Registr ...

  10. excel中将字符转换为数值

    EXCEL表格的左上角那个绿色符号是什么?怎么样可以转换成数值 如果你说的文本是由纯数字组成的,不包含字母和其他字符的话,那么,你要指改为数值可以这样操作:1.先在一个单元格内输入数字12.将刚才输入 ...