1 Star 0 Fork 1

jade_lee/wechat_spider

forked from stoneqp/wechat_spider 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
index.js 1.38 KB
一键复制 编辑 原始数据 按行查看 历史
李强 提交于 2020-01-06 23:01 . 优化
'use strict';
const AnyProxy = require('anyproxy');
const exec = require('child_process').exec;
const ip = require('ip');
const config = require('./config');
const utils = require('./utils');
const logger = require('./utils/logger');
const {
anyproxy: anyproxyConfig,
serverPort,
} = config;
// 引导安装 HTTPS 证书
if (!AnyProxy.utils.certMgr.ifRootCAFileExists()) {
AnyProxy.utils.certMgr.generateRootCA((error, keyPath) => {
if (!error) {
const certDir = require('path').dirname(keyPath);
logger.info('The cert is generated at %s', certDir);
const isWin = /^win/.test(process.platform);
if (isWin) {
exec('start .', { cwd: certDir });
} else {
exec('open .', { cwd: certDir });
}
} else {
logger.error(error);
}
});
}
const proxyServer = new AnyProxy.ProxyServer({
...anyproxyConfig,
// 所有的抓取规则
rule: require('./rule'),
});
proxyServer.on('ready', () => {
const ipAddress = ip.address();
logger.info('请配置代理: %s:8101', ipAddress);
});
proxyServer.on('error', (e) => {
logger.error(e);
});
// 删除 redis 中对应缓存后再启动
utils.delCrawlLinkCache().then(() => {
proxyServer.start();
}, e => {
logger.error(e);
});
// when finished
// proxyServer.close();
require('./server').listen(serverPort, () => {
logger.info('可视化界面: http://localhost:8104');
});
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/jade_lee/wechat_spider.git
git@gitee.com:jade_lee/wechat_spider.git
jade_lee
wechat_spider
wechat_spider
master

搜索帮助

23e8dbc6 1850385 7e0993f3 1850385