WebCollector内核开发——定制Http请求

本教程介绍了如何在WebCollector 2.27及以上版本中定制Http请求,包括在BreadthCrawler插件中添加Cookie、UserAgent等头部信息。对于更深度的定制,可以通过创建自己的Executor利用HttpClient。此外,还讲解了使用Selenium进行网页爬取以获取JS加载的信息。最后,鼓励喜欢WebCollector的用户通过捐款支持项目维护。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本教程适用于WebCollector 2.27版本或更高。

在WebCollector中,使用最多的爬取器应该是BreadthCrawler,BreadthCrawler是用WebCollector的内核开发的一个插件,并不属于内核。

如果只是简单定制Http请求,例如加入Cookie、UserAgent等Http头,使用POST操作等,使用BreadthCrawler插件即可完成,可以参考教程WebCollector自定义http请求

对于一些需要深度定制Http请求的用户,基于WebCollector的内核进行开发是一个不错的选择。基于内核的开发并不难,用户只要自己定义一个Executor即可,下面的例子使用HttpClient定制WebCollector的Http请求:

import cn.edu.hfut.dmic.webcollector.crawldb.DBManager;
import cn.edu.hfut.dmic.webcollector.crawler.Crawler;
import cn.edu.hfut.dmic.webcollector.fetcher.Executor;
import cn.edu.hfut.dmic.webcollector.model.CrawlDatum;
import cn.edu.hfut.dmic.webcollector.model.CrawlDatums;
import cn.edu.hfut.dmic.webcollector.plugin.berkeley.BerkeleyDBManager;
import cn.edu.hfut.dmic.webcollector.util.CharsetDetector;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;


/**
 * Created by hu on 2016/2/19.
 * 该教程为W
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值