Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何定时自动执行 #22

Closed
dsgvsn opened this issue May 12, 2023 · 6 comments
Closed

如何定时自动执行 #22

dsgvsn opened this issue May 12, 2023 · 6 comments

Comments

@dsgvsn
Copy link

dsgvsn commented May 12, 2023

No description provided.

@NaiboWang
Copy link
Owner

NaiboWang commented May 13, 2023

程序本身支持通过命令行方式执行, 所以可以通过操作系统本身自带的定时程序来运行程序,举例说明:

Windows定时执行方式请往下继续看文字版或者看此B站教程:https://www.bilibili.com/video/BV1N94y1a7Lp/

MacOS或Linux下通过以下命令直接执行任务:

image
./easyspider_executestage --id 17 --user_data 1 --server_address http://localhost:8074 --config_folder "/Users/naibowang/Library/Application Support/EasySpider/"

则我们可以在任意目录下,如/Users/username目录下创建一个easyspider_routine.sh文件,内容如下:

cd /Users/naibowang/Downloads/easyspider_macos_all_arch # 这里是你的easyspider_executestage程序所在的文件路径
./easyspider_executestage --id 17 --user_data 1 --server_address http://localhost:8074 --config_folder "/Users/naibowang/Library/Application Support/EasySpider/" # 执行命令

则我们可以直接将此脚本放入crontab定时器中设置定时执行即可:

crontab -e

设置规则,如每12小时执行一次:

0 */12 * * *  bash /Users/username/easyspider_routine.sh

即可完成定时执行。

记得EasySpider本体程序不要关(即下图),否则连不上本地服务器:

image

image

可以看下面的MacOS的执行示例:

https://www.bilibili.com/video/BV1E34y137fT/

@dsgvsn
Copy link
Author

dsgvsn commented May 13, 2023

好的了解了,我去找找windows上的替代品

@NaiboWang
Copy link
Owner

NaiboWang commented May 13, 2023

Windows定时执行方式请往下继续看文字版或者看此B站教程:https://www.bilibili.com/video/BV14V4y1m7iL/

Windows上先建立一个easyspider_routine.ps1的powershell文件,将命令行中的提示命令粘贴,示例命令如下:

cd D:\Documents\Projects\EasySpider\Releases\EasySpider_windows_amd64\
./EasySpider/resources/app/chrome_win64/easyspider_executestage.exe --id [53] --user_data 0 --server_address http://localhost:8074 --config_folder "D:\Documents\Projects\EasySpider\Releases\EasySpider_windows_amd64/" --headless 0 --read_type remote --config_file_name config.json --saved_file_name 

然后通过以下教程设置计划任务定时执行此.ps1文件即可:
https://blog.51cto.com/hzc2012/6000044
https://www.51ittech.com/knowledge-base/create-windows-automatic-timed-execution-of-ps-scripts/
https://www.cnblogs.com/sui776265233/p/13602893.html

如果将上面的--read_type remote改成--read_type local则可以实现不打开EasySpider本体程序的情况下定时执行任务。

@NaiboWang
Copy link
Owner

NaiboWang commented May 13, 2023

Windows x64下想要使用命令行执行程序,需要以下操作:

  1. 调用任务时在下方获得任务执行号,记住这个执行ID

image

  1. 打开命令行程序,进入EasySpider文件夹,并输入命令:
./EasySpider/resources/app/chrome_win64/easyspider_executestage.exe --id 4 --user_data 1 --server_address http://localhost:8074

image
image

其中,--id后面跟的是第一步得到的执行ID--user_data为1则为带用户配置的浏览器,配置目录地址写在了上图config.json文件的absolute_user_data_folder字段中;为0则为纯净版浏览器。

image


Windows x32位下使用命令行,只需将上面命令路径中的chrome_win64改为chrome_win32即可:

./EasySpider/resources/app/chrome_win32/easyspider_executestage.exe --id 4 --user_data 1 --server_address http://localhost:8074

@NaiboWang NaiboWang changed the title 能否增加定时自动执行功能 如何定时自动执行 Jun 10, 2023
@Zeniubius
Copy link

mac 有没有办法实现,不打开程序本体的情况下,执行任务呢,像 Windows 一样,我试了把 --read_type local 改成这种,貌似不行

@NaiboWang
Copy link
Owner

mac 有没有办法实现,不打开程序本体的情况下,执行任务呢,像 Windows 一样,我试了把 --read_type local 改成这种,貌似不行

MacOS需要在easyspider_executestage同级文件夹建立一个tasks文件夹,然后把任务的.json文件拷贝进来,也就是你执行任务时候提示的Application Support/EasySpider/tasks文件夹里的.json文件,然后--read_type local即可。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants