惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Security Archives - TechRepublic
Security Archives - TechRepublic
W
WeLiveSecurity
Hacker News: Ask HN
Hacker News: Ask HN
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
H
Heimdal Security Blog
Help Net Security
Help Net Security
T
Troy Hunt's Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
N
News | PayPal Newsroom
TaoSecurity Blog
TaoSecurity Blog
T
Threat Research - Cisco Blogs
NISL@THU
NISL@THU
G
GRAHAM CLULEY
S
Security @ Cisco Blogs
The Hacker News
The Hacker News
SecWiki News
SecWiki News
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Simon Willison's Weblog
Simon Willison's Weblog
C
Cisco Blogs
A
Arctic Wolf
S
Securelist
Hacker News - Newest:
Hacker News - Newest: "LLM"
AI
AI
N
News and Events Feed by Topic
L
LINUX DO - 热门话题
P
Privacy & Cybersecurity Law Blog
Google Online Security Blog
Google Online Security Blog
T
The Exploit Database - CXSecurity.com
The Last Watchdog
The Last Watchdog
S
Secure Thoughts
Webroot Blog
Webroot Blog
Scott Helme
Scott Helme
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cisco Talos Blog
Cisco Talos Blog
S
Schneier on Security
Latest news
Latest news
T
Threatpost
K
Kaspersky official blog
Know Your Adversary
Know Your Adversary
Schneier on Security
Schneier on Security
I
Intezer
PCI Perspectives
PCI Perspectives
S
Security Affairs
爱范儿
爱范儿
GbyAI
GbyAI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

卡卡罗特

最后代码 | 卡卡罗特 swagger文档 | 卡卡罗特 react脚手架开发 | 卡卡罗特 python的对象增强 | 卡卡罗特 langchain实现Agent | 卡卡罗特 03.python列表集合元组字典 | 卡卡罗特 python依赖打包 | 卡卡罗特 python的异步 | 卡卡罗特 python的生成器 | 卡卡罗特 eino整合Tools | 卡卡罗特 eino实现Agent | 卡卡罗特 eino整合RAG | 卡卡罗特 docker打包go服务 | 卡卡罗特 01-docker入门 | 卡卡罗特 docker-compose | 卡卡罗特 dockerfile | 卡卡罗特 linux安装docker | 卡卡罗特 hertz中间件 | 卡卡罗特 go整合向量数据库ChromaDB | 卡卡罗特 langchainjs | 卡卡罗特 ollama调用各大模型 | 卡卡罗特 spring-ai | 卡卡罗特 自定义一个MCP | 卡卡罗特 context.Context是什么? | 卡卡罗特 01-Bing每日一图接口 | 卡卡罗特 02-腾讯API高清QQ头像https调用接口 | 卡卡罗特 openCV初体验 | 卡卡罗特 RWMutex读写锁 | 卡卡罗特 SyncMap的使用 | 卡卡罗特 defer的使用 | 卡卡罗特
01-获取指定网站的所有的链接 | 卡卡罗特
2026-04-26 · via 卡卡罗特

需求就是获取指定网站内的所有的url,这个还是有难度的,因为需要一层一层递归遍历进去,然后各种判断提取,如果自己手撸的话会消耗很长的时间,好在java有现成的框架 来帮助我们快速实现。

crawler4j实现

依赖

xml

<dependency>
    <groupId>edu.uci.ics</groupId>
    <artifactId>crawler4j</artifactId>
    <version>4.4.0</version>
</dependency>

代码实现

java

import edu.uci.ics.crawler4j.crawler.Page;
import edu.uci.ics.crawler4j.crawler.WebCrawler;
import edu.uci.ics.crawler4j.url.WebURL;

import java.util.regex.Pattern;

public class MyCrawler extends WebCrawler {

    // 过滤掉这些结尾的静态资源
    private final static Pattern FILTERS = Pattern.compile(".*(\\.(css|js|gif|jpg"
                                                           + "|png|mp3|mp4|zip|gz))$");
    // 重写shouldVisit方法,决定哪些URL应该被访问
    @Override
    public boolean shouldVisit(Page referringPage, WebURL url) {
        String href = url.getURL().toLowerCase();
        return !FILTERS.matcher(href).matches()
               && href.startsWith("https://blog.share888.top/");
    }

    // 重写visit方法,定义每次访问一个URL时的行为
    @Override
    public void visit(Page page) {
        String url = page.getWebURL().getURL();
        System.out.println(url);
    }
}

测试代码

java

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import edu.uci.ics.crawler4j.crawler.CrawlConfig;
import edu.uci.ics.crawler4j.crawler.CrawlController;
import edu.uci.ics.crawler4j.fetcher.PageFetcher;
import edu.uci.ics.crawler4j.robotstxt.RobotstxtConfig;
import edu.uci.ics.crawler4j.robotstxt.RobotstxtServer;
import org.junit.Test;
import org.slf4j.LoggerFactory;

import java.util.List;

public class Test {
    static {
        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
        List<Logger> loggerList = loggerContext.getLoggerList();
        loggerList.forEach(logger -> {
            logger.setLevel(Level.INFO);
        });
    }
    @Test
    public void test() throws Exception {
        // 定义数据存储的路径
        String crawlStorageFolder = "/data/crawl";
        // 定义要启动的爬虫数量
        int numberOfCrawlers = 7;

        // 创建CrawlConfig对象,并设置数据存储路径
        CrawlConfig config = new CrawlConfig();
        config.setCrawlStorageFolder(crawlStorageFolder);

        // 创建PageFetcher对象,用于抓取网页
        PageFetcher pageFetcher = new PageFetcher(config);
        // 创建RobotstxtConfig和RobotstxtServer对象,用于处理robots.txt文件
        RobotstxtConfig robotstxtConfig = new RobotstxtConfig();
        RobotstxtServer robotstxtServer = new RobotstxtServer(robotstxtConfig, pageFetcher);
        // 创建CrawlController对象,用于控制爬虫的启动和管理
        CrawlController controller = new CrawlController(config, pageFetcher, robotstxtServer);

        // 添加种子URL
        controller.addSeed("https://blog.share888.top/");
        // 启动爬虫
        controller.start(MyCrawler.class, numberOfCrawlers);
    }
}