Comments (4)
可以参考一下标准库 database/sql
的实现:在 database/sql/driver
下定义了驱动的要实现的 interface
,然后在 database/sql
中有一个 Register
函数来把某个具体的驱动注册到 database/sql
下,这样,使用者就不用关心驱动是如何实现的,只需要知道有什么驱动即可。而且,由于有 Register
函数,所以,在实现驱动时,可以在包的初始化函数 init
中自动进行注册,使用者只需要导入即可,其它的什么都不用做。
标准库 database/sql
是个很好借鉴的例子。
from proxypool.
@xgfone 提了建议之后,我认真想了想,其实目前的代码对于注册一个新的代理采集接口,其实改动很小,只需要在getter包下新增一个采集函数,甚至可以不需要新建一个文件(新建文件是为了方便归档采集函数),
// 5u.go
// Data5u get ip from data5u.com
func Data5u() (result []*models.IP) {
//处理逻辑
...
log.Println("Data5u done.")
return
}
然后在main.go的run函数中添加或删除该采集函数
funs := []func() []*models.IP{
getter.Data5u,
getter.IP66,
getter.KDL,
getter.GBJ,
getter.Xici,
getter.XDL,
//getter.IP181,
//getter.YDL,
getter.PLP,
}
对主体程序改动其实并不大。
from proxypool.
可能目前急需要解决的是,建立一个采集出错的处理机制,自动摒弃掉出错的采集函数,而不影响全局。因为几次碰到有小伙伴说编译程序出错,检测代码后发现都是被采集网站改了或者是无法访问了,造成了代码出错。
from proxypool.
已实现简单的容错机制,即便爬虫出错了也不会影响到主体程序的运行。出错的采集进程会被主线程忽略,其它正常的采集进程仍将继续工作。
from proxypool.
Related Issues (20)
- go get 时候报错 undefined: clog.CONSOLE HOT 3
- 检查数据库中的ip的时候为什么不循环一直去检测,而是只检测一次? HOT 5
- 强烈建议贴出依赖库的版本号~~
- 都用go了,直接把代理功能加上不更好么? HOT 1
- /v2/ip 各种空指针 HOT 2
- Phantomjs用Docker装了可以用么? HOT 2
- http://ip138.com HOT 5
- 程序能运行,但数据库一直没数据 HOT 3
- 数据库没有数据,访问端口也不出来数据 HOT 1
- 一点建议 HOT 1
- 这里有个拼写错误 HOT 1
- bug ?
- Additional Proxy Source
- clog维护不行 建议移除这个依赖
- 博主有联系方式吗?想谈合作~
- 能不能把sqlite驱动换成纯go的,cgo版本的驱动编译比较慢,而且交叉编译会比较麻烦 HOT 1
- 替换htmlquery版本
- htmlquery.Find应该要处理返回的err参数,现在的处理方式可能会导致null pointer错误
- 源码运行 no logger is available HOT 2
- 请求商务推广合作
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proxypool.