送给师弟师妹最好的礼物!全组文献自由就靠这个脚本了
前言
科研通如果你不知道是什么的话,其实他就是一个文献求助平台。某些期刊的文献你无法下载的话,可以在那里发布文献求助,可以很快获取完整文献。对于研究人员而言,我还是很推荐的。
脚本的话是去年写的了,主要还是在科研通上签到太麻烦了,我就尝试使用自动化的方法寻求解决方案了。
其实更多的是,我个人信奉一个理论:如果一个事情需要重复做,且占用时间超过 15 秒,那么你就需要考虑自动化去完成了。
当时我集中弄了两个自动化的解决方案:
- 基于本地浏览器的可视化编程自动化脚本(只能实现单用户签到)
- 基于 Python 自动化签到脚本(实现多用户批量同时签到,给你的师弟师妹最好的礼物🤣)
这两个解决方案各有优缺点,我会在最后简单说明,对于懒得部署使用的同学,也可以填写我创建的收集表,提供相关的信息,我可以公益在服务器上批量签到。
解决方案
本地浏览器
这个解决方案是基于本地浏览器进行的,是利用了开源的浏览器插件 Automa 。这个插件可以实现模块化,可视化的编程实现在浏览器上的任何自动化操作。
插件安装去官网访问安装即可,Free ~
我的实现思路很简单
- 首先在后台打开新的标签页
- 访问科研通网站(前提是你已经登陆过一次了)
- 判断签到按钮对象是否存在
- 存在就点击签到
- 然后关闭这个后台标签页
最后设置,脚本每天早上和晚上自动执行即可。唯一的缺点就是因为脚本是基于浏览器插件的,所以你需要保持电脑不关机,而且浏览器后台在运行中。
如果有伙伴需要,脚本内容是
1 | {"extVersion":"1.29.12","name":"科研通签到","icon":"riGlobalLine","table":[{"id":"HCTZH","name":"FindButton","type":"boolean"}],"version":"1.29.4","drawflow":{"edges":[{"class":"connected-edges","data":{},"events":{},"id":"vueflow__edge-w1ihw9xw1ihw9x-output-1-aoc2mlhaoc2mlh-input-1","label":"","markerEnd":"arrowclosed","selectable":true,"source":"w1ihw9x","sourceHandle":"w1ihw9x-output-1","sourceX":308,"sourceY":155.5,"target":"aoc2mlh","targetHandle":"aoc2mlh-input-1","targetX":268.9789930555555,"targetY":367.09225694444444,"type":"custom","updatable":true},{"data":{},"events":{},"id":"vueflow__edge-6nan3v16nan3v1-output-1-0sqh02d0sqh02d-input-1","label":"","markerEnd":"arrowclosed","selectable":true,"source":"6nan3v1","sourceHandle":"6nan3v1-output-1","sourceX":1540,"sourceY":94.5,"target":"0sqh02d","targetHandle":"0sqh02d-input-1","targetX":1586.8406293402777,"targetY":133.86472985161677,"type":"custom","updatable":true},{"data":{},"events":{},"id":"vueflow__edge-0sqh02d0sqh02d-output-1-ttjxxeyttjxxey-input-1","label":"","markerEnd":"arrowclosed","selectable":true,"source":"0sqh02d","sourceHandle":"0sqh02d-output-1","sourceX":1818.8406293402777,"sourceY":133.86472985161677,"target":"ttjxxey","targetHandle":"ttjxxey-input-1","targetX":1892,"targetY":94.5,"type":"custom","updatable":true},{"animated":true,"data":{},"events":{},"id":"vueflow__edge-plm5dvtplm5dvt-output-GxtVebFC-ispzULroHP-f-oho8o7doho8o7d-input-1","label":"","markerEnd":"arrowclosed","selectable":true,"source":"plm5dvt","sourceHandle":"plm5dvt-output-GxtVebFC-ispzULroHP-f","sourceX":989,"sourceY":256.88751220703125,"target":"oho8o7d","targetHandle":"oho8o7d-input-1","targetX":1058.8839930555555,"targetY":427.04993055555553,"type":"custom","updatable":true},{"data":{},"events":{},"id":"vueflow__edge-plm5dvtplm5dvt-output-JgR92FfMkn4gGjwPHiPFy-wgimrzvwgimrzv-input-1","label":"","markerEnd":"arrowclosed","selectable":true,"source":"plm5dvt","sourceHandle":"plm5dvt-output-JgR92FfMkn4gGjwPHiPFy","sourceX":989,"sourceY":208.8874969482422,"target":"wgimrzv","targetHandle":"wgimrzv-input-1","targetX":1016,"targetY":104.5,"type":"custom","updatable":true},{"data":{},"events":{},"id":"vueflow__edge-wgimrzvwgimrzv-output-1-6nan3v16nan3v1-input-1","label":"","markerEnd":"arrowclosed","selectable":true,"source":"wgimrzv","sourceHandle":"wgimrzv-output-1","sourceX":1248,"sourceY":104.5,"target":"6nan3v1","targetHandle":"6nan3v1-input-1","targetX":1308,"targetY":94.5,"type":"custom","updatable":true},{"class":"connected-edges","data":{},"events":{},"id":"vueflow__edge-aoc2mlhaoc2mlh-output-1-plm5dvtplm5dvt-input-1","label":"","markerEnd":"arrowclosed","selectable":true,"source":"aoc2mlh","sourceHandle":"aoc2mlh-output-1","sourceX":500.9789930555555,"sourceY":367.09225694444444,"target":"plm5dvt","targetHandle":"plm5dvt-input-1","targetX":692,"targetY":222.1875,"type":"custom","updatable":true},{"class":"connected-edges","data":{},"events":{},"id":"vueflow__edge-aoc2mlhaoc2mlh-output-1-8f2ubfm8f2ubfm-input-1","label":"","markerEnd":"arrowclosed","selectable":true,"source":"aoc2mlh","sourceHandle":"aoc2mlh-output-1","sourceX":500.9789930555555,"sourceY":367.09225694444444,"target":"8f2ubfm","targetHandle":"8f2ubfm-input-1","targetX":663,"targetY":471.6999816894531,"type":"custom","updatable":true}],"nodes":[{"data":{"active":false,"customUserAgent":false,"description":"科研通","disableBlock":false,"inGroup":false,"onError":{"dataToInsert":[],"enable":false,"insertData":false,"retry":false,"retryInterval":2,"retryTimes":1,"toDo":"error"},"settings":{"blockTimeout":0,"debugMode":false},"tabZoom":1,"updatePrevTab":false,"url":"https://www.ablesci.com/","userAgent":"","waitTabLoaded":true},"events":{},"id":"aoc2mlh","label":"new-tab","position":{"x":288.9789930555555,"y":331.09225694444444},"type":"BlockBasic"},{"data":{"activeInInput":false,"contextMenuName":"","contextTypes":[],"date":"","days":[],"delay":5,"description":"","disableBlock":false,"interval":60,"isUrlRegex":false,"observeElement":{"baseElOptions":{"attributeFilter":[],"attributes":false,"characterData":false,"childList":true,"subtree":false},"baseSelector":"","matchPattern":"","selector":"","targetOptions":{"attributeFilter":[],"attributes":false,"characterData":false,"childList":true,"subtree":false}},"parameters":[],"preferParamsInTab":false,"settings":{"blockTimeout":0,"debugMode":false},"shortcut":"","time":"00:00","triggers":[{"data":{"days":[{"id":0,"times":["09:00:00","15:00:00","21:00:00"]},{"id":1,"times":["09:00:00","15:00:00","21:00:00"]},{"id":3,"times":["09:00:00","15:00:00","21:00:00"]},{"id":5,"times":["09:00:00","15:00:00","21:00:00"]},{"id":2,"times":["09:00:00","15:00:00","21:00:00"]},{"id":6,"times":["09:00:00","15:00:00","21:00:00"]},{"id":4,"times":["09:00:00","15:00:00","21:00:00"]}],"time":"00:00"},"id":"nA9WZ","type":"specific-day"}],"type":"manual","url":""},"events":{},"id":"w1ihw9x","label":"trigger","position":{"x":96,"y":119.5},"type":"BlockBasic"},{"data":{"$breakpoint":false,"description":"签到","disableBlock":false,"findBy":"cssSelector","markEl":false,"multiple":false,"onError":{"dataToInsert":[],"enable":true,"insertData":false,"retry":false,"retryInterval":2,"retryTimes":1,"toDo":"error"},"selector":"button.layui-btn-danger","settings":{"blockTimeout":0,"debugMode":false},"waitForSelector":false,"waitSelectorTimeout":5000},"events":{},"id":"6nan3v1","label":"event-click","position":{"x":1328,"y":58.5},"type":"BlockBasic"},{"data":{"$breakpoint":false,"activeTab":false,"allWindows":false,"closeType":"tab","description":"","disableBlock":false,"url":"https://www.ablesci.com/"},"events":{},"id":"ttjxxey","label":"close-tab","position":{"x":1912,"y":58.5},"type":"BlockBasic"},{"data":{"$breakpoint":false,"disableBlock":false,"settings":{"blockTimeout":0,"debugMode":false},"time":500},"events":{},"id":"0sqh02d","label":"delay","position":{"x":1606.8406293402777,"y":75.17722222222224},"type":"BlockDelay"},{"data":{"$breakpoint":false,"activeTab":true,"allWindows":false,"closeType":"tab","description":"","disableBlock":false,"onError":{"dataToInsert":[],"enable":false,"insertData":false,"retry":false,"retryInterval":2,"retryTimes":1,"toDo":"error"},"settings":{"blockTimeout":0,"debugMode":false},"url":""},"events":{},"id":"oho8o7d","label":"close-tab","position":{"x":1078.8839930555555,"y":391.04993055555553},"type":"BlockBasic"},{"data":{"$breakpoint":false,"conditions":[{"conditions":[{"conditions":[{"id":"J88WeJNy8pw9tl2V8lcIC","items":[{"category":"value","data":{"selector":"/html/body/div[5]/div/div[2]/div[1]/div/div[3]/div[2]/button"},"id":"VPQ6eLLF9alGv3P2POJ_M","type":"element#exists"}]}],"id":"3o1ZdDZq0ADTkfqKTZAh5"}],"id":"JgR92FfMkn4gGjwPHiPFy","name":"元素存在"},{"conditions":[{"conditions":[{"id":"BSjfza7z1Pl3PHHDsiwGw","items":[{"category":"value","data":{"selector":"/html/body/div[5]/div/div[2]/div[1]/div/div[3]/div[2]/button"},"id":"kUF3PLEboOAsBaWgx787-","type":"element#notExists"}]}],"id":"bjVuEXNXfo5hiKRjsxjdH"}],"id":"GxtVebFC-ispzULroHP-f","name":"元素不存在"}],"description":"","disableBlock":false,"retryConditions":false,"retryCount":10,"retryTimeout":1000,"settings":{"blockTimeout":0,"debugMode":false}},"events":{},"id":"plm5dvt","label":"conditions","position":{"x":712,"y":119.5},"type":"BlockConditions"},{"data":{"dataList":[{"action":"default","filePath":"","isFile":false,"name":"HCTZH","type":"table","value":"True"}],"description":"","disableBlock":false,"onError":{"dataToInsert":[],"enable":false,"errorMessage":"","insertData":false,"retry":false,"retryInterval":2,"retryTimes":1,"toDo":"error"},"settings":{"blockTimeout":0,"debugMode":false}},"events":{},"id":"wgimrzv","label":"insert-data","position":{"x":1036,"y":68.5},"type":"BlockBasic"},{"data":{"description":"","disableBlock":false,"iconUrl":"","imageUrl":"","message":"","title":"Hello world!"},"events":{},"id":"8f2ubfm","label":"notification","position":{"x":683,"y":435.6999816894531},"type":"BlockBasic"}],"position":[0,0],"viewport":{"x":0,"y":0,"zoom":1},"zoom":1},"settings":{"blockDelay":0,"debugMode":false,"defaultColumnName":"column","execContext":"popup","executedBlockOnWeb":false,"inputAutocomplete":true,"insertDefaultColumn":false,"notification":true,"onError":"stop-workflow","publicId":"","restartTimes":3,"reuseLastState":false,"saveLog":true,"tabLoadTimeout":30000},"globalData":"{\n\t\"key\": \"value\"\n}","description":"","includedWorkflows":{}} |
你只需要把这个内容保存为 json 文件,然后导入 Automa 插件里面就可以了。
但是我不得不提醒,他的最新版的这个插件,对于自动点击触发逻辑应该是变化了,现在他需要标签页获取焦点才会点击,所以要么下载老版本,要不就需要微调一下自动点击的逻辑。
很明显,这不是最优解决方案哈哈哈,因为你会关电脑,你也有可能几天不用电脑。所以我们的终极解决方案在下面
Python 自动化
这个是目前的终极解决方案,脚本功能包括:
- 批量多用户签到
- 签到结果通知到用户微信消息
- 管理员获取全部的用户签到结果,以应对突发签到报错
- 每日定时执行
- 不需要本地,完全运行在云端,一次部署,无需操作
这样就可以一次性给各位朋友,师哥师姐,师弟师妹们一起签到了(😀
云端签到运行主要是借助于:阿里云的云函数(当然腾讯云也可以)。
实际上这个功能在阿里云上的全称是:函数计算 FC,它是是一种事件驱动的全托管计算服务,开发者无需管理服务器等基础设施,只需编写并上传代码,函数计算便会自动准备计算资源,并以弹性、可靠的方式运行代码。
函数计算默认按照资源使用量计费,根据函数配置的规格与使用时长的乘积计算资源使用量,仅在需要时分配资源并能及时释放。
微信通知借助于:Server酱服务。
它是一款「手机」和「服务器」、「智能设备」之间的通信软件。说人话就是从服务器、路由器等设备上推消息到手机的工具。
最终实现效果就是每日定时给多用户签到,签到完成后会通知每个用户签到结果。稳定性而言,一次部署在我这里已经稳定运行 259 天了。
因为微信公众号不允许挂外部链接,所以相关服务直接百度就能找到
数据准备
在开始签到之前,我们需要提供相关的数据以自动化脚本,主要是两个信息:
- 科研通的
cookie:它代表了你在科研通服务器上的身份,负责通过这个信息模拟是你在签到 - Server酱的
SendKey:它代表了你在 Server 酱上的身份,负责通过这个信息给用户本人发送通知
科研通的cookie获取方式
- 打开你的浏览器的开发者模式,你可以通过
F12快捷键打开,或者相关设置里面打开(每个浏览器可能略微不同) - 打开你的科研通网站(或者你也可以先访问科研通网站,然后再打开科研通网站)
- 找到【网络】,如果这个列表是空的,刷新一下网页就有了
- 找到科研通的这个页面,在标头里面找到
Cookie项,复制整个值即可(每个人不一样,长短内容)
Server 酱的SendKey 获取
比较简单,只需要用户注册登录后,在Key&API栏找到自己的 SendKey 即可。
至此,你的数据准备工作就完成了。接下来就是脚本了。
脚本内容
1 | # 作者:Maxwell Lei |
当然你也可以通过整个脚本,在本地执行,不过这样就南辕北辙了不是。你可以直接和我一样,部署到云函数上,这样就可以实现,一次部署,自动签到,不需要考虑别的了。
公益服务
如果上述的内容你都不想尝试自己部署,我可以提供批量签到公益服务,毕竟我的云函数部署着一个也是签到,两个也是签到,您可以填写下面的收集表,该收集表仅7天内有效,我会给你实现自动签到。
下面的链接和上面的二维码是一个,你可以选择访问链接一样的:【腾讯文档】科研通自动签到
https://docs.qq.com/form/page/DUXJaaFBsbkNwRVJP
结语
脚本很好,请狠狠的使用,不要让文献拖延家人们的科研步伐啊!!
最近有点忙,更新会有点慢,做了一些有趣的代码实验和我个人维护的软件更新。腾出时间会写点东西,以记录下来。
参考内容
本篇内容无任何参考内容







