Comments (108)
依赖jsoncpp和spdlog库,你需要安装这两个库。
我对manjaro不是很熟悉,手头也没有该系统的环境测试,你可以在网上找一下相关教程,或者去这两个库的官网看一下,编译源码安装。然后在xmake.lua中修改这两个库的路径。
README文档中有写该项目依赖的第三方库,给出了官网或github项目地址。
PS. 这个工程中,Server、Client、MysqlDatabase、代理IP池是紧密相依的,必须都搭建好好才能运行。如果不是想爬取大量数据的话,不建议构建/运行这个工程,但是里面的一些代码是可以参考的(BiliUserSpiderClient/src/bili目录下的代码)
from biliuserspider.
收到,谢谢!
晚点我安装好这两个库
再根据README指导尝试
话说README已经很详细了
奈何非专业人士不知怎么开门
from biliuserspider.
xmake.lua中修改这两个库的路径
请问是修改"1"、"2"、“3”三处吗?
-- link flags
add_linkdirs("1")
add_links("2", "mysqlclient", "curl", "pthread", "3")
from biliuserspider.
是的
from biliuserspider.
是的
"mysqlclient", "curl"是否需要同样操作呢?
"pthread"印象当中应该是没有安装过的
from biliuserspider.
pthread在linux下本来就有的,mysqlclient,curl也是需要自行安装的库(libmysqlclient)
from biliuserspider.
已完成编译安装:
open-source-parsers/Jsoncpp: 解析Json。添加了几个实用函数 (src/json/json.h)
gabime/spdlog: 日志库。进行了简单封装 (src/log/logger.h)
未完成编译安装:
libmysql: MySQL官方的C API。进行了简单封装 (src/database/mysql_instance.h)
hongliuliao/ehttp: Http server。This library make http (with json) microservice easy!
Leopard-C/iclient: 封装的libcurl,进行http请求。(个人仓库)
报错:
运行命令:
make && make test && ./output/bin/hello_server 3456
报错提示:
bash: ./output/bin/hello_server: 没有那个文件或目录
大大录个视频吧,纯净系统怎么一步一步安装、设置相关文件,最终把程序跑起来。
B站爬虫相关的文件基本上翻了个遍,对比后最想用的是你跟BiliOB(被官方警告删除代码了)的程序
之前使用 DataABC 的 weibo-search 和 weiboSpider 设置好 cookie 和 数据库登陆信息就能跑了
https://github.com/dataabc/weiboSpider/blob/master/docs/cookie.md
因为readme里面标注服务器运行环境Linux,想着换成linux折腾起来应该会简单点
结果折腾了几天还是不得其法,求救…
from biliuserspider.
可以给你录制个视频,但是必须是ubuntu系统,可以吗?(我可以新建个干净的ubuntu虚拟机,一步步来)
from biliuserspider.
可以给你录制个视频,但是必须是ubuntu系统,可以吗?(我可以新建个干净的ubuntu虚拟机,一步步来)
好的,非常感谢
from biliuserspider.
可以给你录制个视频,但是必须是ubuntu系统,可以吗?(我可以新建个干净的ubuntu虚拟机,一步步来)
程序成功能正常运行后,我会抽时间把视频,整理成脑图或者文字教程,希望更多有同样需求的小白们,能跟着教程一步步调教好程序,实现自己的需求
from biliuserspider.
视频和库文件下载链接:https://cowtransfer.com/s/e7f83a16c06245
解压密码:0301ba53710650bb99af28778e12efcb
你最好先完整一遍视频再决定要不要继续用这个工程,真的很复杂,尤其时windows下面!
from biliuserspider.
(视频中)这家代理IP质量不行了,考虑换其他代理IP吧。另外这个项目应该不会再维护,短期内没有这方面的需求了。
from biliuserspider.
视频和库文件下载链接:https://cowtransfer.com/s/e7f83a16c06245
解压密码:0301ba53710650bb99af28778e12efcb你最好先完整一遍视频再决定要不要继续用这个工程,真的很复杂,尤其时windows下面!
收到!
非常感谢您在百忙之中,抽空录制这个视频教程!我会先完整过一遍视频,再边看边根据视频步骤进行操作。
另外:祝您和家人新年快乐,诸事顺利!
from biliuserspider.
(视频中)这家代理IP质量不行了,考虑换其他代理IP吧。另外这个项目应该不会再维护,短期内没有这方面的需求了。
那真是太可惜了:对比了100多个B站爬虫项目,您的代码应该是效率最高、功能最全的三个之一,且其中一个还被官方警告删除代码了
from biliuserspider.
视频在手机上刷完了,准备爬起来给本子做系统装mysql&vs2017,一步一步跟着视频操作了
from biliuserspider.
XShell连VirtualBox,一会儿能连上一会儿又连不上,重装了几次系统,到做教程就掉链子,无奈换了Hyper-V,一番调教之后竟然稳定连接了。。。
from biliuserspider.
cp vimrc ~/.vimrc
vim
之后,又报错了,回来再整
输入vim回车后报错:
Error detected while processing /home/cream/.vimrc:
line 274:
E484: Can't open file /home/cream/.vim/snippets.vim
Press ENTER or type command to continue
后面的步骤虽然也进去了,但是不知道会不会有什么其他问题
from biliuserspider.
两种解决方法
- 你把icDotfiles中的snippets.vim复制到~/.vim即可
- 注释掉~/.vimrc最后一行 (snippets.vim是自定义的快捷键,写markdown文件用的,写其他文件用不到)
from biliuserspider.
两种解决方法
- 你把icDotfiles中的snippets.vim复制到~/.vim即可
- 注释掉~/.vimrc最后一行 (snippets.vim是自定义的快捷键,写markdown文件用的,写其他文件用不到)
收到,谢谢!
按道理来说,0.install_ubuntu_server和1.prepare_ubuntu这两个视频应该是可以跳过的
(比如:安装 zsh & oh my zsh)
但是不知道为什么跳过的话,xmake那个地方过不去,只好严格按照视频一步一步设置
from biliuserspider.
图文教程(未完成):
https://www.notion.so/1-Ubuntu-4ee60ee187a3467992539cd0e428f586
还有很多细节待完善,目前自己也没有走完整个设置流程
且编写教程过程中碰到很多问题,所以进度可能会非常慢
from biliuserspider.
①
source ~/.zshrc
xmake
报错:
checking for architecture ... x86_64
[ 5%]: ccache compiling.release src/server/http-parser/http_parser.c
[ 8%]: ccache compiling.release src/server/multipart-parser-c/multipart_parser.c
[ 11%]: ccache compiling.release src/iclient/ic_util.cpp
[ 14%]: ccache compiling.release src/iclient/ic_executor.cpp
error: src/iclient/ic/ic_curl_inc.h:1:10: fatal error: curl/curl.h: No such file or directory
#include <curl/curl.h>
compilation terminated.
warning: target(bilispider_server).add_linkdirs("/usr/local/lib/spdlog") path not found at ./xmake.lua:11
②
sudo apt install libjsoncpp-dev
xmake
报错:
[ 5%]: ccache compiling.release src/iclient/ic_util.cpp
[ 8%]: ccache compiling.release src/iclient/ic_executor.cpp
error: src/iclient/ic/ic_curl_inc.h:1:10: fatal error: curl/curl.h: No such file or directory
#include <curl/curl.h>
compilation terminated.
warning: target(bilispider_server).add_linkdirs("/usr/local/lib/spdlog") path not found at ./xmake.lua:11
from biliuserspider.
sudo apt install libcurl4-openssl-dev
from biliuserspider.
sudo apt install libcurl4-openssl-dev
这些已经过了,现在卡在mysql workbench,估计是安装完mysql后要启动数据库相关服务
from biliuserspider.
sudo apt install libcurl4-openssl-dev
这些已经过了,现在卡在mysql workbench,估计是安装完mysql后要启动数据库相关服务
通过搜索解决了:
MySQL及MySQL-workbench安装
from biliuserspider.
安装Qt差点把我整吐了,换了n个版本,突然发现全都不对,要下载5.12.6版本的文件,3.7G我哭了...
我想说一句:python大法好
from biliuserspider.
总算把Qt搞定了,需要断网安装。
安装后需要在VS-Qt VS Tools-Qt Versions里设置qmake.exe的路径
from biliuserspider.
报错:
bin/bilispider_server
[06:44:12] [error] ProxyConfig is invalid <config.cpp> <g_parse_from_json> <205>
[06:44:12] [error] Read configuration failed <main.cpp> <63>
出错代码及操作:
vim config/config.json
设置"database"参数:
17行 "host":"127.0.0.1",--此处有疑问:视频中填写的"10.133.89.92",但是不知道这个ip是怎么获取的,为什么是这个ip?
18行 "name":"bili_user_test",
19行 "password":"安装MySQL时设置的密码",
设置"proxy"参数:
25行 "interval_query":10,
25行 "orderid":"",--订单ID未设置
26行 "user_id":"",--用户ID未设置
设置"server"参数:
29行 "admin_password":"",--已填写
33行 "ip":"["127.0.0.1","10.0.2.15"]",-- ifconfig 获取到的
35行 "port":"10033",--应该是要在VirtualBox里设置网络
设置完后执行报错:
bin/bilispider_server
from biliuserspider.
报错:
bin/bilispider_server
[06:44:12] [error] ProxyConfig is invalid <config.cpp> <g_parse_from_json> <205>
[06:44:12] [error] Read configuration failed <main.cpp> <63>出错代码及操作:
vim config/config.json
设置"database"参数:
17行 "host":"127.0.0.1",--此处有疑问:视频中填写的"10.133.89.92",但是不知道这个ip是怎么获取的,为什么是这个ip?
18行 "name":"bili_user_test",
19行 "password":"安装MySQL时设置的密码",设置"proxy"参数:
25行 "interval_query":10,
25行 "orderid":"",--订单ID未设置
26行 "user_id":"",--用户ID未设置设置"server"参数:
29行 "admin_password":"",--已填写
33行 "ip":"["127.0.0.1","10.0.2.15"]",-- ifconfig 获取到的
35行 "port":"10033",--应该是要在VirtualBox里设置网络设置完后执行报错:
bin/bilispider_server
埃尔云代理好像是挂了,所以订单ID跟用户ID空着没填,不知道报错跟这个是否有关
from biliuserspider.
database中的ip,就是Mysql所在主机的IP。(linux使用ifconfig命令,windows下使用ipconfig命令)
proxy中的 “order_id"必须设置才能启动,”user_id"可选。
from biliuserspider.
好像确实挂了,那你试着换一家代理IP,蜻蜓代理(我也用过两次,还行)
from biliuserspider.
from biliuserspider.
在 BiliUserSpiderServer/src/manager/proxy_manager.cpp 中
from biliuserspider.
database中的ip,就是Mysql所在主机的IP。(linux使用ifconfig命令,windows下使用ipconfig命令)
proxy中的 “order_id"必须设置才能启动,”user_id"可选。
database中的ip,就是Mysql所在主机的IP。(linux使用ifconfig命令,windows下使用ipconfig命令)
proxy中的 “order_id"必须设置才能启动,”user_id"可选。
明白了,那我应该获取的是Windows下的ip
from biliuserspider.
在 BiliUserSpiderServer/src/manager/proxy_manager.cpp 中
收到~
重做了干净的系统在做教程
我把整个流程先尽量走一遍
中途改教程改的我痛不欲生
我尽量缩减掉不必要的操作
from biliuserspider.
Visual Studio 已经走到最后一步了
单击 " 本地 Windows 调试器 " 报错
看你回复才发现原来可以上传图片…
from biliuserspider.
我发给你的教程文件里面有这几个文件
from biliuserspider.
我发给你的教程文件里面有这几个文件
是的我看到了,那几个文件夹都有设置,这几个dll好像没有设置过
from biliuserspider.
我发给你的教程文件里面有这几个文件
是的我看到了,那几个文件夹都有设置,这几个dll好像没有设置过
有设置过libmysql.lib,dll文件没印象
from biliuserspider.
不是放在这里,是放在上一级目录,或者bin目录
from biliuserspider.
不是放在这里,是放在上一级目录,或者bin目录
原来如此
from biliuserspider.
不是放在这里,是放在上一级目录,或者bin目录
我有点懵逼了
我截的图是源代码
VS项目在另外一个盘
应该是把lib文件夹
放到VS项目文件夹中吧?
from biliuserspider.
from biliuserspider.
放到这两个目录中的任何一个
from biliuserspider.
放到这两个目录中的任何一个
收到
from biliuserspider.
放到这两个目录中的任何一个
复制 lib 文件夹下的 5 个 .dll 文件
粘贴在VisualStudio项目文件夹的
BiliUserSpiderAdmin\x64\Debug\
from biliuserspider.
https://proxy.horocn.com/
https://www.qingtingip.com/
这两个哪个是...
李逵碰到李鬼
from biliuserspider.
https://proxy.horocn.com/
怎么感觉贵了,还是少了个套餐,我记得我买的是18一天的
from biliuserspider.
哎,这种代理IP提供商,一个商家好几个网站(也就简单的换换界面),不买这个是吧,那你买另一个,咦,还是我的,哈哈哈
from biliuserspider.
https://proxy.horocn.com/
怎么感觉贵了,还是少了个套餐,我记得我买的是18一天的
估计是调价了。埃尔云跟你录视频时的价格也不一样,刚注册好准备买就发现它挂了
from biliuserspider.
哎,这种代理IP提供商,一个商家好几个网站(也就简单的换换界面),不买这个是吧,那你买另一个,咦,还是我的,哈哈哈
就像qs网站的站群
或者淘宝、拼多多店群
私密代理、隧道代理
貌似是选择私密代理?
from biliuserspider.
是的
from biliuserspider.
还要按照下图设置BiliUserSpiderServer/src/manager/proxy_manager.cpp,对吧
from biliuserspider.
在Visual Studio中的BiliUserSpiderServer项目中找到了/src/manager/proxy_manager.cpp,但是没有AiErYun和QingTing的相关代码,不知道是不是找错了文件
from biliuserspider.
BiliUserSpiderServer这个工程只能在Linux上编译运行
from biliuserspider.
BiliUserSpiderServer这个工程只能在Linux上编译运行
只修改第17行,把USE_AiErYun改成USE_QingTing,对吗
from biliuserspider.
是不是因为用的试用代理所以报错?
[19:11:05] [info] Get configuration ok
[19:11:05] [error] Mysql Error: Access denied for user 'root'@'192.168.2.3' (using password: YES) <mysql_pool.cpp> <114>
[19:11:05] [info] Mysql pool init successfully
[19:11:05] [error] Connect to mysql database failed <spidermanager.cpp> <105>
[19:11:05] [info] Connect to server ok!
from biliuserspider.
是的
from biliuserspider.
是不是因为用的试用代理所以报错?
[19:11:05] [info] Get configuration ok
[19:11:05] [error] Mysql Error: Access denied for user 'root'@'192.168.2.3' (using password: YES) <mysql_pool.cpp> <114>
[19:11:05] [info] Mysql pool init successfully
[19:11:05] [error] Connect to mysql database failed <spidermanager.cpp> <105>
[19:11:05] [info] Connect to server ok!
连接数据库是不是失败了,Mysql需要开启远程访问的功能(默认是只能localhost访问的)
from biliuserspider.
连接数据库是不是失败了,Mysql需要开启远程访问的功能(默认是只能localhost访问的)
host设为127.0.0.1就可以连上,应该是安装mysql的时候选择了localhost
from biliuserspider.
from biliuserspider.
看起来像Windows端连上了mysql,Linux端没连上?
from biliuserspider.
from biliuserspider.
改了权限后要重启Mysql,应该不是代码的问题,要不你从虚拟机里使用命令行连接主机上的Mysql,看看可不可以。(昨晚在复习考试,没开电脑,所以没看到消息)
from biliuserspider.
改了权限后要重启Mysql,应该不是代码的问题,要不你从虚拟机里使用命令行连接主机上的Mysql,看看可不可以。(昨晚在复习考试,没开电脑,所以没看到消息)
嗯嗯,好的谢谢!
等会儿我试试看
from biliuserspider.
好像还是代理的问题
代码是已经改过了呀
Proxy type: AiErYun
bin/bilispider_server
[05:22:10] [info] Read configuration ok
Running Tasks: 0
Recycled Tasks: 0
[05:22:10] [info] bind for ip:127.0.0.1 success
[05:22:10] [info] bind for ip:10.0.2.15 success
[05:22:10] [info] start Server Socket on port : 10033
Construct ProxyManager
[05:24:50] [info] Mysql pool init successfully
[05:24:50] [info] Proxy type: AiErYun
[05:24:50] [info] Server started
BgThread AiErYun started!
Living clients: 0
[05:24:54] [error] GET Error: http://www.lyunplus.com/api/proxy/list?count=20&format=json&orderCode=XUO61688116516888528 <proxy_manager.cpp> <152>
[05:24:54] [error] iclient Status: TIMEOUT <proxy_manager.cpp> <153>
[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:24:56] [error] errorCount:12 <proxy_manager.cpp> <179>
ProxyManager BgThread AiErYun quit. g_isRunning: {}
ClientManager BgThread quit. g_isRunning: false
[05:25:15] [info] Mysql pool init successfully
[05:25:15] [info] Proxy type: AiErYun
BgThread AiErYun started!
[05:25:15] [info] Server started
Living clients: 0
[05:25:15] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:25:15] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:25:15] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:24:50] [info] Proxy type: AiErYun[05:24:50] [info] Server started
BgThread AiErYun started!Living clients: 0
[05:24:54] [error] GET Error: http://www.lyunplus.com/api/proxy/list?count=20&format=json&orderCode=XUO61688116516888528 <proxy_manager.cpp> <152>[05:24:54] [error] iclient Status: TIMEOUT <proxy_manager.cpp> <153>
[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:24:56] [error] Code is 10112 <proxy_manager.cpp> <173>[05:24:56] [error] errorCount:12 <proxy_manager.cpp> <179>
ProxyManager BgThread AiErYun quit. g_isRunning: {}ClientManager BgThread quit. g_isRunning: false
[05:25:15] [info] Mysql pool init successfully
[05:25:15] [info] Proxy type: AiErYun
BgThread AiErYun started!
[05:25:15] [info] Server started
Living clients: 0
[05:25:15] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:25:15] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:25:15] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:25:15] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:25:15] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:25:15] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:25:15] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:25:15] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:25:15] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:25:15] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:25:15] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:25:15] [error] Code is 10112 <proxy_manager.cpp> <173>
[05:25:15] [error] errorCount:12 <proxy_manager.cpp> <179>
ProxyManager BgThread AiErYun quit. g_isRunning: {}
ClientManager BgThread quit. g_isRunning: false
from biliuserspider.
GET Error: http://www.lyunplus.com/api/proxy/list?count=20&format=json&orderCode=XUO61688116516888528 <proxy_manager.cpp> <152>
这个链接前半部分还是埃尔云的,是不是这里的问题
from biliuserspider.
BiliUserSpiderServer/src/manager/proxy_manager.cpp
我看一下你的这个文件
from biliuserspider.
from biliuserspider.
退出程序后,这个文件夹没有了。。。
是不是因为我没有打开VS2017直接运行的BiliUserSpiderAdmin.exe
`# cream @ cream in ~/dev/cpp/BiliUserSpider on git:master x [6:53:55] C:1
$ cd /src
cd: no such file or directory: /src
cream @ cream in ~/dev/cpp/BiliUserSpider on git:master x [6:54:07] C:1
$ cd src
cd: no such file or directory: src
`
from biliuserspider.
?? BiliUserSpiderServer是在Linux上编译运行的啊,和Windows下的VS没关系
from biliuserspider.
我在重新编译这个文件,稍等
from biliuserspider.
编译后打开还是空的...
这是服务器出问题了?
from biliuserspider.
是 src/... 不是 /src/...
你最前面多打了个 "/"
from biliuserspider.
是 src/... 不是 /src/...
你最前面多打了个 "/"
嗯嗯,刚找到这段代码了,手打还是容易出错
cd ~/dev/cpp/BiliUserSpider/BiliUserSpiderServer
vim src/manager/proxy_manager.cpp
from biliuserspider.
from biliuserspider.
你把 start() 函数贴出来
from biliuserspider.
埃尔云可以在微信和小米浏览器(骑x墙x)打开,
电脑不论(骑x墙x)与否都看不到套餐等页面
from biliuserspider.
你把它截全,或者直接复制代码过来
from biliuserspider.
vim的复制有点蛋疼
找了半天不知道怎么复制出来哈哈
from biliuserspider.
命令行 cat xxx.cpp 然后复制。
from biliuserspider.
#include "proxy_manager.h"
#include "../log/logger.h"
#include "../json/json.h"
#include "../util/string_utils.h"
#include "../iclient/ic/ic.h"
#include "../mysql/mysql_instance.h"
#include "../mysql/mysql_pool.h"
#include "../config/config.h"
#include "../global.h"
#include <jsoncpp/json/json.h>
#include
#include
void backgroundThreadAiErYun(ProxyManager* mgr);
void backgroundThreadQingTing(ProxyManager* mgr);
#define USE_QingTing
ProxyManager::ProxyManager() {
LogF("Construct ProxyManager");
}
ProxyManager::~ProxyManager() {
int count = 50;
#ifdef USE_AiErYun
while (--count && !bg_thread_AiErYun_quit_) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
#else
ifdef USE_QingTing
while (--count && !bg_thread_QingTing_quit_) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
endif
#endif
LogF("Destruct ProxyManager");
}
void ProxyManager::start() {
std::lock_guardstd::mutex lck(mutex_);
if (mysql_db_pool_) {
LWarn("mysql_db_pool_ is not NULL. ProxyManager maybe started already.");
return;
}
mysql_db_pool_ = new MysqlDbPool(g_dbConfig.host, g_dbConfig.port,
g_dbConfig.user, g_dbConfig.password,
g_dbConfig.name, 1);
#ifdef USE_AiErYun
LInfo("Proxy type: AiErYun");
if (bg_thread_AiErYun_quit_) {
bg_thread_AiErYun_quit_ = false;
std::thread t(backgroundThreadAiErYun, this);
t.detach();
}
#else
ifdef USE_QingTing
LInfo("Proxy type: QingTing");
if (bg_thread_AiErYun_quit_) {
bg_thread_QingTing_quit_ = false;
std::thread t(backgroundThreadQingTing, this);
t.detach();
}
endif
#endif
}
void ProxyManager::stop() {
g_stop();
std::lock_guardstd::mutex lck(mutex_);
if (mysql_db_pool_) {
delete mysql_db_pool_;
mysql_db_pool_ = nullptr;
}
}
/* 添加新的代理ip到数据库 /
bool ProxyManager::addProxies(const std::vectoric::ProxyData& proxies) {
char sql = new char[64 + 32 * proxies.size()];
char* end = sql;
end += sprintf(end, "INSERT IGNORE INTO proxy (host
,port
) VALUE");
for (auto& proxyData : proxies) {
end += sprintf(end, "('%s',%u),", proxyData.host.c_str(), proxyData.port);
}
*(end-1) = ';';
*end = '\0';
/* 尝试5次 */
bool ret = false;
for (int i = 0; i < 5; ++i) {
MysqlInstance mysql(mysql_db_pool_);
if (mysql.bad() || !mysql.exec(sql)) {
continue;
}
else {
ret = true;
break;
}
}
delete[] sql;
return ret;
}
/* 清除数据库中失败较次数多的代理 */
bool ProxyManager::removeProxies() {
char sql[64];
sprintf(sql, "DELETE FROM proxy WHERE error_count
>%d;", g_clientConfig.proxy_max_error_times);
bool ret = false;
for (int i = 0; i < 5; ++i) {
MysqlInstance mysql(mysql_db_pool_);
if (mysql.bad() || !mysql.exec(sql)) {
continue;
}
else {
ret = true;
break;
}
}
return ret;
}
/****************************************************************************
*
-
获取代理
-
1. 埃尔云代理
-
2. 蜻蜓代理
****************************************************************************/
/* 埃尔云代理 /
void backgroundThreadAiErYun(ProxyManager mgr) {
LogF("BgThread AiErYun started!");
int errorCount = 0;
while (g_isRunning) {
ic::Url url("http://www.lyunplus.com/api/proxy/list");
url.setParam("orderCode", g_proxyConfig.order_id);
url.setParam("count", 10);
url.setParam("format", "json");
ic::Request request(url.toString());
request.setVerifySsl(false);
request.setTimeout(3000);
auto response = request.perform();
if (response.getStatus() != ic::Status::SUCCESS ||
response.getHttpStatus() != ic::http::StatusCode::HTTP_200_OK)
{
LError("GET Error: {}", url.toString());
LError("iclient Status: {}", ic::to_string(response.getStatus()));
if (errorCount++ > 10) {
LError("errorCount:{}", errorCount);
break;
}
std::this_thread::sleep_for(std::chrono::seconds(2));
continue;
}
Json::Reader reader;
Json::Value root;
if (!reader.parse(response.getData(), root, false)) {
LError("Parse json failed");
continue;
}
if (checkNull(root, "code")) {
LError("Missing param:code");
continue;
}
std::string code = getStrVal(root, "code");
if (code != "0") {
LError("Code is {}", code);
if (code == "10130") {
std::this_thread::sleep_for(std::chrono::seconds(3));
}
else {
if (errorCount++ > 10) {
LError("errorCount:{}", errorCount);
break;
}
}
continue;
}
if (checkNull(root, "data")) {
LError("Missing param: data");
errorCount++;
continue;
}
auto& data = root["data"];
if (data.empty()) {
LError("No ip returned");
errorCount++;
continue;
}
int error = false;
int size = data.size();
std::vector<ic::ProxyData> proxiesData;
proxiesData.reserve(size);
for (int i = 0; i < size; ++i) {
auto& proxy = data[i];
if (checkNull(proxy, "port", "ip")) {
LError("Missing param: port/ip");
error = true;
break;
}
ic::ProxyData proxyData;
proxyData.host = getStrVal(proxy, "ip");
std::string port_str = getStrVal(proxy, "port");
proxyData.port = std::atoi(port_str.c_str());
//LogF("%s:%u", host.c_str(), port);
proxiesData.emplace_back(proxyData);
}
LogF("-----------------------------");
if (error) {
errorCount++;
continue;
}
{
std::lock_guard<std::mutex> lck(mgr->mutex_);
if (!mgr->addProxies(proxiesData)) {
LError("Add proxies failed");
break;
}
LogF("Add %d proxies", proxiesData.size());
if (!mgr->removeProxies()) {
LError("Remove proxies failed");
break;
}
LogF("Remove proxies ok");
}
errorCount = 0;
/* 间隔指定时间调用代理IP服务商的API */
int count = g_proxyConfig.interval_query * 10;
for (int i = 0; i < count && g_isRunning; ++i) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
LogF("ProxyManager BgThread AiErYun quit. g_isRunning: {}", g_isRunning);
mgr->bg_thread_AiErYun_quit_ = true;
mgr->stop();
}
/* 蜻蜓代理 /
void backgroundThreadQingTing(ProxyManager mgr) {
LogF("BgThread QingTing started!");
int errorCount = 0;
while (g_isRunning) {
ic::Url url("https://proxyapi.horocn.com/api/v2/proxies");
url.setParam("order_id", g_proxyConfig.order_id);
url.setParam("num", "10");
url.setParam("format", "json");
url.setParam("line_separator", "win");
url.setParam("can_repeat", "yes");
url.setParam("loc_name", "**");
url.setParam("user_token", g_proxyConfig.user_id);
ic::Request request(url.toString());
request.setVerifySsl(false);
request.setTimeout(3000);
auto response = request.perform();
if (response.getStatus() != ic::Status::SUCCESS ||
response.getHttpStatus() != ic::http::StatusCode::HTTP_200_OK)
{
LError("GET Error: {}", url.toString());
LError("iclient Status: {}", ic::to_string(response.getStatus()));
if (errorCount++ > 10) {
LError("errorCount:{}", errorCount);
break;
}
std::this_thread::sleep_for(std::chrono::seconds(2));
continue;
}
Json::Reader reader;
Json::Value root;
if (!reader.parse(response.getData(), root, false)) {
LError("Parse json failed");
continue;
}
if (checkNull(root, "code", "msg")) {
LError("Missing param:code/msg");
continue;
}
bool code = getBoolVal(root, "code");
if (code != 0) {
LError("Code is {}", code);
if (errorCount++ > 10) {
LError("errorCount: {}", errorCount);
break;
}
continue;
}
if (checkNull(root, "data")) {
LError("Missing param: data");
errorCount++;
continue;
}
auto& data = root["data"];
if (data.empty()) {
LError("Get IP dataset empty");
errorCount++;
continue;
}
int error = false;
int size = data.size();
std::vector<ic::ProxyData> proxiesData;
proxiesData.reserve(size);
for (int i = 0; i < size; ++i) {
auto& proxy = data[i];
if (checkNull(proxy, "host", "port")) {
LError("Missing param: host/port");
error = true;
break;
}
ic::ProxyData proxyData;
proxyData.host = getStrVal(proxy, "host");
std::string port_str = getStrVal(proxy, "port");
proxyData.port = std::atoi(port_str.c_str());
//LogF("%s:%u", host.c_str(), port);
proxiesData.emplace_back(proxyData);
}
LogF("-----------------------------");
if (error) {
errorCount++;
continue;
}
{
std::lock_guard<std::mutex> lck(mgr->mutex_);
if (!mgr->addProxies(proxiesData)) {
LError("Add proxies failed");
break;
}
LogF("Add %d proxies", proxiesData.size());
if (!mgr->removeProxies()) {
LError("Remove proxies failed");
break;
}
LogF("Remove proxies ok");
}
errorCount = 0;
/* 间隔指定时间调用代理IP服务商的API */
int count = g_proxyConfig.interval_query * 10;
for (int i = 0; i < count && g_isRunning; ++i) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
LogF("ProxyManager BgThread QingTing quit. g_isRunning: %s", g_isRunning ? "true" : "false");
mgr->bg_thread_QingTing_quit_ = true;
mgr->stop();
}
from biliuserspider.
LInfo("Proxy type: QingTing");
if (bg_thread_AiErYun_quit_) {
bg_thread_QingTing_quit_ = false;
把 if
里面的 bg_thread_AiErYun_quit_
的改成 bg_thread_QingTing_quit_
, 一个小bug,但是你这个问题应该不是这个bug的原因。
你再编译运行一下试试
from biliuserspider.
好的,需要重建个服务器编译吗
from biliuserspider.
需要
from biliuserspider.
这里你是怎么保存退出的呢,我之前是直接Ctrl+C,是不是跟这一步有关
from biliuserspider.
这是什么?
from biliuserspider.
这是什么?
cat > ohmyzsh.sh
复制install.sh代码
粘贴 Shift + Insert
退出 Ctrl + C
bash ohmyzsh.sh
from biliuserspider.
输完后,敲个回车,然后ctrl + D
from biliuserspider.
这里应该是安装&配置ohmyzsh终端?
from biliuserspider.
安装zsh不是必须的,只是我习惯用zsh而已。
$ cat > xxx.cpp
balabala
bala
[Ctrl + D]
from biliuserspider.
嗯呢,教程你有时间看下,里面应该有部分操作可以删减的
我根据视频和自己的操作删减了部分,但应该还有优化空间
from biliuserspider.
linux下的git速度感人。。。
修改了host
代理地址都好慢
前两天还蛮快的
git clone https://github.com.cnpmjs.org/gabime/spdlog.git
Cloning into 'spdlog'...
remote: Enumerating objects: 31, done.
remote: Counting objects: 100% (31/31), done.
remote: Compressing objects: 100% (25/25), done.
Receiving objects: 62% (13486/21568), 4.75 MiB | 13.00 KiB/s
from biliuserspider.
[09:04:20] [info] Read configuration ok
Running Tasks: 0
Recycled Tasks: 0
[09:04:20] [info] bind for ip:127.0.0.1 success
[09:04:20] [info] bind for ip:10.0.2.15 success
[09:04:20] [info] start Server Socket on port : 10033
Construct ProxyManager
[09:04:48] [info] Mysql pool init successfully
[09:04:48] [info] Proxy type: AiErYun
[09:04:48] [info] Server started
BgThread AiErYun started!
Living clients: 0
[09:04:51] [error] GET Error: http://www.lyunplus.com/api/proxy/list?count=20&format=json&orderCode=PBZ41688217567292430 <proxy_manager.cpp> <152>
[09:04:51] [error] iclient Status: TIMEOUT <proxy_manager.cpp> <153>
[09:04:53] [error] Code is 10112 <proxy_manager.cpp> <173>
[09:04:54] [error] Code is 10112 <proxy_manager.cpp> <173>
[09:04:54] [error] Code is 10112 <proxy_manager.cpp> <173>
[09:04:54] [error] Code is 10112 <proxy_manager.cpp> <173>
[09:04:54] [error] Code is 10112 <proxy_manager.cpp> <173>
[09:04:54] [error] Code is 10112 <proxy_manager.cpp> <173>
[09:04:54] [error] Code is 10112 <proxy_manager.cpp> <173>
[09:04:54] [error] Code is 10112 <proxy_manager.cpp> <173>
[09:04:54] [error] Code is 10112 <proxy_manager.cpp> <173>
[09:04:54] [error] Code is 10112 <proxy_manager.cpp> <173>
[09:04:54] [error] Code is 10112 <proxy_manager.cpp> <173>
[09:04:54] [error] errorCount:12 <proxy_manager.cpp> <179>
ProxyManager BgThread AiErYun quit. g_isRunning: {}
ClientManager BgThread quit. g_isRunning: false
from biliuserspider.
from biliuserspider.
不是的,你这明显还是用的埃尔云代理啊。你怎么启动的程序, bin/bilispider_server ? 是不是启动的是原来的程序 。
我就把宏定义那里改一下,就变成蜻蜓代理了。
from biliuserspider.
不是的,你这明显还是用的埃尔云代理啊。你怎么启动的程序, bin/bilispider_server ? 是不是启动的是原来的程序 。
我就把宏定义那里改一下,就变成蜻蜓代理了。
Windows端要修改吗?
from biliuserspider.
不用啊,使用哪家代理必须在启动服务器时指定(代码写死的),启动后不能修改。
from biliuserspider.
from biliuserspider.
老哥,晚点能远程吗,我快要崩溃了…
cream @ cream in ~/dev/cpp/BiliUserSpider/BiliUserSpiderServer on git:master x [9:59:32]
$ bin/bilispider_server[09:59:37] [info] Read configuration okRunning Tasks: 0
-------------------------------Recycled Tasks: 0
[09:59:37] [info] bind for ip:127.0.0.1 success[09:59:37] [info] bind for ip:10.0.2.15 success[09:59:37] [info] start Server Socket on port : 10033
Construct ProxyManager[10:01:19] [info] Mysql pool init successfully
[10:01:19] [info] Proxy type: QingTing[10:01:19] [info] Server startedBgThread QingTing started!
Living clients: 0[10:01:23] [error] GET Error: http://lyunplus.com/api/proxy/list?can_repeat=yes&format=json&line_separator=win&loc_name=%E4%B8%AD%E5%9B%BD&num=10&order_id=PBZ41688217567292430&user_token= <proxy_manager.cpp> <273>
[10:01:23] [error] iclient Status: TIMEOUT <proxy_manager.cpp> <274>
[10:01:25] [error] GET Error: http://lyunplus.com/api/proxy/list?can_repeat=yes&format=json&line_separator=win&loc_name=%E4%B8%AD%E5%9B%BD&num=10&order_id=PBZ41688217567292430&user_token= <proxy_manager.cpp> <273>
[10:01:25] [error] iclient Status: SUCCESS <proxy_manager.cpp> <274>
[10:01:27] [error] GET Error: http://lyunplus.com/api/proxy/list?can_repeat=yes&format=json&line_separator=win&loc_name=%E4%B8%AD%E5%9B%BD&num=10&order_id=PBZ41688217567292430&user_token= <proxy_manager.cpp> <273>
[10:01:27] [error] iclient Status: SUCCESS <proxy_manager.cpp> <274>
[10:01:29] [error] GET Error: http://lyunplus.com/api/proxy/list?can_repeat=yes&format=json&line_separator=win&loc_name=%E4%B8%AD%E5%9B%BD&num=10&order_id=PBZ41688217567292430&user_token= <proxy_manager.cpp> <273>
[10:01:29] [error] iclient Status: SUCCESS <proxy_manager.cpp> <274>
Living clients: 0
[10:01:32] [error] GET Error: http://lyunplus.com/api/proxy/list?can_repeat=yes&format=json&line_separator=win&loc_name=%E4%B8%AD%E5%9B%BD&num=10&order_id=PBZ41688217567292430&user_token= <proxy_manager.cpp> <273>
[10:01:32] [error] iclient Status: SUCCESS <proxy_manager.cpp> <274>
[10:01:34] [error] GET Error: http://lyunplus.com/api/proxy/list?can_repeat=yes&format=json&line_separator=win&loc_name=%E4%B8%AD%E5%9B%BD&num=10&order_id=PBZ41688217567292430&user_token= <proxy_manager.cpp> <273>
[10:01:34] [error] iclient Status: SUCCESS <proxy_manager.cpp> <274>
[10:01:36] [error] GET Error: http://lyunplus.com/api/proxy/list?can_repeat=yes&format=json&line_separator=win&loc_name=%E4%B8%AD%E5%9B%BD&num=10&order_id=PBZ41688217567292430&user_token= <proxy_manager.cpp> <273>
[10:01:36] [error] iclient Status: SUCCESS <proxy_manager.cpp> <274>
[10:01:38] [error] GET Error: http://lyunplus.com/api/proxy/list?can_repeat=yes&format=json&line_separator=win&loc_name=%E4%B8%AD%E5%9B%BD&num=10&order_id=PBZ41688217567292430&user_token= <proxy_manager.cpp> <273>
[10:01:38] [error] iclient Status: SUCCESS <proxy_manager.cpp> <274>
[10:01:40] [error] GET Error: http://lyunplus.com/api/proxy/list?can_repeat=yes&format=json&line_separator=win&loc_name=%E4%B8%AD%E5%9B%BD&num=10&order_id=PBZ41688217567292430&user_token= <proxy_manager.cpp> <273>
[10:01:40] [error] iclient Status: SUCCESS <proxy_manager.cpp> <274>
Living clients: 0
[10:01:43] [error] GET Error: http://lyunplus.com/api/proxy/list?can_repeat=yes&format=json&line_separator=win&loc_name=%E4%B8%AD%E5%9B%BD&num=10&order_id=PBZ41688217567292430&user_token= <proxy_manager.cpp> <273>
[10:01:43] [error] iclient Status: SUCCESS <proxy_manager.cpp> <274>
[10:01:45] [error] GET Error: http://lyunplus.com/api/proxy/list?can_repeat=yes&format=json&line_separator=win&loc_name=%E4%B8%AD%E5%9B%BD&num=10&order_id=PBZ41688217567292430&user_token= <proxy_manager.cpp> <273>
[10:01:45] [error] iclient Status: SUCCESS <proxy_manager.cpp> <274>
[10:01:47] [error] GET Error: http://lyunplus.com/api/proxy/list?can_repeat=yes&format=json&line_separator=win&loc_name=%E4%B8%AD%E5%9B%BD&num=10&order_id=PBZ41688217567292430&user_token= <proxy_manager.cpp> <273>
[10:01:47] [error] iclient Status: SUCCESS <proxy_manager.cpp> <274>
[10:01:47] [error] errorCount:12 <proxy_manager.cpp> <276>
ProxyManager BgThread QingTing quit. g_isRunning: true
ClientManager BgThread quit. g_isRunning: false
from biliuserspider.
好
from biliuserspider.
Related Issues (1)
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 biliuserspider.