欢迎使用 Selenops,一个 Swift 网页爬虫。
给定一个网页 URL 和要搜索的词语,Selenops 将在该页面及其链接的所有页面中递归地查找该词语。
import Selenops
// Initialize crawler.
let crawler = Crawler(
startURL: URL(string: "https://fivestars.blog/")!,
maximumPagesToVisit: 10,
wordToSearch: "Swift" // Specify the word to search here.
)
// Set delegate.
crawler.delegate = ... // Needs to conform to CrawlerDelegate
// Start crawling!
crawler.start()
crawler
代理将获取信息,例如已访问的网页,以及在哪些网页中找到了指定的词语。
Selenops 通过 Swift Package Manager 分发
要在应用程序中使用它,请按照 本教程 操作,并使用此仓库 URL:https://github.com/zntfdr/Selenops.git
。
要在 package 中使用它,请将其作为依赖项添加到您的 Package.swift
中
let package = Package(
...
dependencies: [
.package(url: "https://github.com/zntfdr/Selenops.git", from: "2.0.0")
],
targets: [
.target(
...
dependencies: ["Selenops"])
],
...
)
...然后在需要时使用 import Selenops
即可。
Selenops 还附带一个命令行工具,展示其功能。
要安装它,请克隆项目并运行 make
$ git clone https://github.com/zntfdr/Selenops.git
$ cd Selenops
$ make
Selenops 由 Federico Zanetello 构建,作为 Swift 脚本的示例。
欢迎并鼓励所有用户积极参与项目的持续开发——通过修复他们遇到的任何错误,或改进任何被发现不足的文档。
如果您想做出更改,请打开一个 Pull Request,即使它仅包含您计划的更改草稿,或重现问题的测试。
感谢您,请尽情享用 Selenops!