• Stars
    star
    7,471
  • Rank 4,878 (Top 0.1 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created almost 9 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Pholcus is a distributed high-concurrency crawler software written in pure golang

Pholcus GitHub release report card github issues github closed issues GoDoc

Pholcus(幽灵蛛)是一款纯 Go 语言编写的支持分布式的高并发爬虫软件,仅用于编程学习与研究。

它支持单机、服务端、客户端三种运行模式,拥有Web、GUI、命令行三种操作界面;规则简单灵活、批量任务并发、输出方式丰富(mysql/mongodb/kafka/csv/excel等);另外它还支持横纵向两种抓取模式,支持模拟登录和任务暂停、取消等一系列高级功能。

image

免责声明

本软件仅用于学术研究,使用者需遵守其所在地的相关法律法规,请勿用于非法用途!! 如在中国大陆频频爆出爬虫开发者涉诉与违规的新闻
郑重声明:因违法违规使用造成的一切后果,使用者自行承担!!

爬虫原理

image

 

image

 

image

框架特点

  • 为具备一定Go或JS编程基础的用户提供只需关注规则定制、功能完备的重量级爬虫工具;
  • 支持单机、服务端、客户端三种运行模式;
  • GUI(Windows)、Web、Cmd 三种操作界面,可通过参数控制打开方式;
  • 支持状态控制,如暂停、恢复、停止等;
  • 可控制采集量;
  • 可控制并发协程数;
  • 支持多采集任务并发执行;
  • 支持代理IP列表,可控制更换频率;
  • 支持采集过程随机停歇,模拟人工行为;
  • 根据规则需求,提供自定义配置输入接口
  • 有mysql、mongodb、kafka、csv、excel、原文件下载共五种输出方式;
  • 支持分批输出,且每批数量可控;
  • 支持静态Go和动态JS两种采集规则,支持横纵向两种抓取模式,且有大量Demo;
  • 持久化成功记录,便于自动去重;
  • 序列化失败请求,支持反序列化自动重载处理;
  • 采用surfer高并发下载器,支持 GET/POST/HEAD 方法及 http/https 协议,同时支持固定UserAgent自动保存cookie与随机大量UserAgent禁用cookie两种模式,高度模拟浏览器行为,可实现模拟登录等功能;
  • 服务器/客户端模式采用Teleport高并发SocketAPI框架,全双工长连接通信,内部数据传输格式为JSON。

下载安装

go get -u -v github.com/henrylee2cn/pholcus

创建项目

package main

import (
    "github.com/henrylee2cn/pholcus/exec"
    // _ "pholcus_lib_pte" // 同样你也可以自由添加自己的规则库
)

func main() {
    // 设置运行时默认操作界面,并开始运行
    // 运行软件前,可设置 -a_ui 参数为"web"、"gui"或"cmd",指定本次运行的操作界面
    // 其中"gui"仅支持Windows系统
    exec.DefaultRun("web")
}

 

编译运行

正常编译方法

cd {{replace your gopath}}/src/github.com/henrylee2cn/pholcus
go install 或者 go build

Windows下隐藏cmd窗口的编译方法

cd {{replace your gopath}}/src/github.com/henrylee2cn/pholcus
go install -ldflags="-H=windowsgui -linkmode=internal" 或者 go build -ldflags="-H=windowsgui -linkmode=internal"

查看可选参数:

pholcus -h

image

 

Web版操作界面截图如下:

image

 

GUI版操作界面之模式选择界面截图如下

image

 

Cmd版运行参数设置示例如下

$ pholcus -_ui=cmd -a_mode=0 -c_spider=3,8 -a_outtype=csv -a_thread=20 -a_dockercap=5000 -a_pause=300
-a_proxyminute=0 -a_keyins="<pholcus><golang>" -a_limit=10 -a_success=true -a_failure=true

 

*注意:*Mac下如使用代理IP功能,请务必获取root用户权限,否则无法通过ping获取可以代理!

 

运行时目录文件

├─pholcus 软件
│
├─pholcus_pkg 运行时文件目录
│  ├─config.ini 配置文件
│  │
│  ├─proxy.lib 代理IP列表文件
│  │
│  ├─spiders 动态规则目录
│  │  └─xxx.pholcus.html 动态规则文件
│  │
│  ├─phantomjs 程序文件
│  │
│  ├─text_out 文本数据文件输出目录
│  │
│  ├─file_out 文件结果输出目录
│  │
│  ├─logs 日志目录
│  │
│  ├─history 历史记录目录
│  │
└─└─cache 临时缓存目录

 

动态规则示例

特点:动态加载规则,无需重新编译软件,书写简单,添加自由,适用于轻量级的采集项目。
xxx.pholcus.html

<Spider>
    <Name>HTML动态规则示例</Name>
    <Description>HTML动态规则示例 [Auto Page] [http://xxx.xxx.xxx]</Description>
    <Pausetime>300</Pausetime>
    <EnableLimit>false</EnableLimit>
    <EnableCookie>true</EnableCookie>
    <EnableKeyin>false</EnableKeyin>
    <NotDefaultField>false</NotDefaultField>
    <Namespace>
        <Script></Script>
    </Namespace>
    <SubNamespace>
        <Script></Script>
    </SubNamespace>
    <Root>
        <Script param="ctx">
        console.log("Root");
        ctx.JsAddQueue({
            Url: "http://xxx.xxx.xxx",
            Rule: "登录页"
        });
        </Script>
    </Root>
    <Rule name="登录页">
        <AidFunc>
            <Script param="ctx,aid">
            </Script>
        </AidFunc>
        <ParseFunc>
            <Script param="ctx">
            console.log(ctx.GetRuleName());
            ctx.JsAddQueue({
                Url: "http://xxx.xxx.xxx",
                Rule: "登录后",
                Method: "POST",
                PostData: "[email protected]&amp;password=44444444&amp;login_btn=login_btn&amp;submit=login_btn"
            });
            </Script>
        </ParseFunc>
    </Rule>
    <Rule name="登录后">
        <ParseFunc>
            <Script param="ctx">
            console.log(ctx.GetRuleName());
            ctx.Output({
                "全部": ctx.GetText()
            });
            ctx.JsAddQueue({
                Url: "http://accounts.xxx.xxx/member",
                Rule: "个人中心",
                Header: {
                    "Referer": [ctx.GetUrl()]
                }
            });
            </Script>
        </ParseFunc>
    </Rule>
    <Rule name="个人中心">
        <ParseFunc>
            <Script param="ctx">
            console.log("个人中心: " + ctx.GetRuleName());
            ctx.Output({
                "全部": ctx.GetText()
            });
            </Script>
        </ParseFunc>
    </Rule>
</Spider>

静态规则示例

特点:随软件一同编译,定制性更强,效率更高,适用于重量级的采集项目。
xxx.go

func init() {
    Spider{
        Name:        "静态规则示例",
        Description: "静态规则示例 [Auto Page] [http://xxx.xxx.xxx]",
        // Pausetime: 300,
        // Limit:   LIMIT,
        // Keyin:   KEYIN,
        EnableCookie:    true,
        NotDefaultField: false,
        Namespace:       nil,
        SubNamespace:    nil,
        RuleTree: &RuleTree{
            Root: func(ctx *Context) {
                ctx.AddQueue(&request.Request{Url: "http://xxx.xxx.xxx", Rule: "登录页"})
            },
            Trunk: map[string]*Rule{
                "登录页": {
                    ParseFunc: func(ctx *Context) {
                        ctx.AddQueue(&request.Request{
                            Url:      "http://xxx.xxx.xxx",
                            Rule:     "登录后",
                            Method:   "POST",
                            PostData: "[email protected]&password=123456&login_btn=login_btn&submit=login_btn",
                        })
                    },
                },
                "登录后": {
                    ParseFunc: func(ctx *Context) {
                        ctx.Output(map[string]interface{}{
                            "全部": ctx.GetText(),
                        })
                        ctx.AddQueue(&request.Request{
                            Url:    "http://accounts.xxx.xxx/member",
                            Rule:   "个人中心",
                            Header: http.Header{"Referer": []string{ctx.GetUrl()}},
                        })
                    },
                },
                "个人中心": {
                    ParseFunc: func(ctx *Context) {
                        ctx.Output(map[string]interface{}{
                            "全部": ctx.GetText(),
                        })
                    },
                },
            },
        },
    }.Register()
}

 

代理IP

  • 代理IP写在/pholcus_pkg/proxy.lib文件,格式如下,一行一个IP:
http://183.141.168.95:3128
https://60.13.146.92:8088
http://59.59.4.22:8090
https://180.119.78.78:8090
https://222.178.56.73:8118
http://115.228.57.254:3128
http://49.84.106.160:9000
  • 在操作界面选择“代理IP更换频率”或命令行设置-a_proxyminute参数,进行使用

  • *注意:*Mac下如使用代理IP功能,请务必获取root用户权限,否则无法通过ping获取可以代理!

 

FAQ

请求队列中,重复的URL是否会自动去重?

url默认情况下是去重的,但是可以通过设置Request.Reloadable=true忽略重复。

URL指向的页面内容若有更新,框架是否有判断的机制?

url页面内容的更新,框架无法直接支持判断,但是用户可以自己在规则中自定义支持。

请求成功是依据web头的状态码判断?

不是判断状态,而是判断服务器有无响应流返回。即,404页面同样属于成功。

请求失败后的重新请求机制?

每个url尝试下载指定次数之后,若依然失败,则将该请求追加到一个类似defer性质的特殊队列中。  
在当前任务正常结束后,将自动添加至下载队列,再次进行下载。如果依然有没下载成功的,则保存至失败历史记录。  
当下次执行该条爬虫规则时,可通过选择继承历史失败记录,把这些失败请求自动加入defer性质的特殊队列……(后面是重复步骤)

More Repositories

1

erpc

An efficient, extensible and easy-to-use RPC framework.
Go
2,496
star
2

faygo

Faygo is a fast and concise Go Web framework that can be used to develop high-performance web app(especially API) with fewer codes. Just define a struct handler, faygo will automatically bind/verify the request parameters and generate the online API doc.
Go
1,593
star
3

lessgo

Lessgo 是一款简单、稳定、高效、灵活的 golang web 开发框架,支持动态路由、自动化API测试文档、热编译、热更新等,实现前后端分离、系统与业务分离,完美兼容MVC与MVVC等多种开发模式,非常利于企业级应用与API接口的开发。[A simple, stable, efficient and flexible web framework.]
Go
479
star
4

goutil

Golang common tool functions and components.
Go
369
star
5

surfer

Package surfer is a high level concurrency http client. It has surf andphantom download engines, highly simulated browser behavior, the function of analog login and so on.
Go
214
star
6

aster

Easily get the golang syntax tree and modify the code.
Go
151
star
7

faydoc

User manual of faygo frame.
117
star
8

gust

A Rust-inspired declarative-programming and generic-type module for Golang that helps avoid bugs and improve development efficiency.
Go
89
star
9

algorithm

algorithm library
Go
58
star
10

erpc-doc

eRPC Documents
Go
55
star
11

tp-micro

TP-Micro is a simple, powerful micro service framework based on Teleport.
Go
54
star
12

pholcus_lib

仅供学习的Pholcus爬虫规则库
Go
43
star
13

ameda

Powerful toolbox for golang data types.
Go
31
star
14

lessgo_demo

A demo of Lessgo.
Go
31
star
15

rester

Fast and concise RESTful web framework based on fasthttp
Go
27
star
16

apiware

Apiware binds the specified parameters of the Golang net/http and fasthttp requests to the structure and verifies the validity of the parameter values.
Go
24
star
17

wasmy

wasmy, easily customize my wasm app!
Rust
22
star
18

lessgoext

Lessgo's expansion module.
Go
22
star
19

timer

Go语言各种定时器的实现。
Go
21
star
20

rpc-benchmark

golang RPC framework benchmark
Go
20
star
21

go-crawler-practice

📕《Go语言爬虫编写实战》
19
star
22

lessgo_doc

Lessgo user's manual.
Go
18
star
23

pool

通用资源池,动态增加资源实例,并支持空闲资源定时回收。
Go
18
star
24

opay

以订单为主线、面向接口开发的在线支付通用模块
Go
17
star
25

mahonia

Copy from http://code.google.com/p/mahonia/
Go
17
star
26

pholcus_dependent

Pholcus第三方依赖包源码下载
Go
16
star
27

gofield

High-performance struct field accessor based on unsafe pointers.
Go
14
star
28

wasmesh

wasmesh is a WebAssembly service mesh framework.
Rust
14
star
29

erpc-book

Handbook of eRPC which is an efficient, extensible and easy-to-use RPC framework.
Go
12
star
30

beelogs

Upgrade from beego logs !
Go
12
star
31

tp-ext

Teleport v3 custom extensions collection.
Go
12
star
32

tconfig

源自beego的升级版配置文件解析库,目前支持解析的文件格式有 ini、json、xml、yaml。
Go
10
star
33

faygos

A micro service framework developed using 'faygo' and 'etcd'
Go
10
star
34

ipc

IPC Inter-Process Communication.
Go
9
star
35

cfgo

Cfgo from the YAML document, bi-directional synchronous multi-module configuration.
Go
9
star
36

beauty-go

Go解答《编程之美》系列
Go
9
star
37

less

lessgo 项目部署工具
Go
9
star
38

TRRW-Chrome-Extension-Template

Use React + TypeScript + Antd + Rust-Wasm to develop Chrome Extension.
TypeScript
8
star
39

flagx

Standard flag package extension with more features, such as struct flag, app framework, etc.
Go
8
star
40

easysync2

The EasySync2 Algorithm
Rust
7
star
41

utils

Go语言中的一些常用函数。
Go
7
star
42

lessgo_dependency

Lessgo‘s dependency package.
Go
7
star
43

env

Package env provides a convenient way to initialize variables from the environment.
Go
7
star
44

currip

currip helps you get current extranet ip or intranet ip.
Go
7
star
45

widerror

Error type with wide attributes, used for API unified error code
Rust
5
star
46

mysql-aes

MySQL Transparent Data Encryption
Go
5
star
47

tp-p2p

A teleport-based p2p application framework that penetrates the intranet through TCP tunnel.
Go
5
star
48

henrylee2cn.github.com

Share Notes !
CSS
5
star
49

option

Go-generics option module inspired by rust.
Go
4
star
50

sulfa

Basic algorithm library implemented by rust.
Rust
4
star
51

lycee

lycee is a key-value storage system being developed for me to learn rust.
Rust
4
star
52

codec_protobuf

Go
4
star
53

chinaid

Make or verify China ID
Go
4
star
54

andeya

3
star
55

slinbo

A personal chat application.
C++
2
star
56

result

Go-generics result module inspired by rust.
Go
2
star
57

sqlab

The project waiting for planning, some SQL tool functions are temporarily deposited.
Go
2
star
58

enum_const

enum const trait
Rust
2
star
59

vscode_debug_go

Configure my own local launch.json to improve ease of use
Go
2
star
60

tiedot

Your NoSQL database powered by Golang
Go
1
star
61

mysqldriver-go

GC optimized MySQL driver
Go
1
star
62

py-layout

Python Project Generator
Python
1
star
63

imgs-repo

我的图床仓库
1
star