Automa 是一个用于 Chrome 浏览器自动化的插件,从自动填写表格、执行重复性任务、截屏、抓取网站数据等等,完全可以根据你自己的需求来决定如何使用。
突然知道了这个小玩意儿,还挺不错的,就玩一下,适合偏WEB自动化工作流的任务(爬虫等),还是挺方便的,这样就不用安装一个大的软件了。
插件下载安装
可以通过谷歌应用商城下载(Automa)
https://chrome.google.com/webstore/detail/automa/infppggnoaenmfagbfknfkancpbljcca?utm_source=chrome-ntp-icon
也可以通过源码构建的方式,直接加载到游览器
https://github.com/AutomaApp/automa/releases/tag/v1.15.1
加载插件完成后
点击就可以使用了
可以通过这个设置,来设置中文显示,这样看着就很方便了。
也可以配置一下箭头效果
还有其他界面可以自己多看看。
要实现的业务逻辑
总得搞个像样的操作,要不然,体现不出来效果。
实现的逻辑
-
1. 触发条件为手动触发
-
2. 触发后,新建一个游览器页签,然后打开抖音
-
3. 把抖音显示的视频新标签页打开
-
4. 同时把此视频下载到本地
流程图大致如下:
各个节点的示意
触发器的选项
我这里没有啥别的条件,我就选择了手动。但是,也可以选择上下文菜单,直接页面右键就可以了。
新建标签页
我这里选的是新打开一个,主要是为了方便测试。
当然,也可以选择活动标签页,也就是当前选择的页面来进行操作,这个节点必须得有。
获取页面的属性值
一个是获取属性值,一个是获取文本值。
这其实是两种概念。
如果 HTML是下图,那么,应该选文本值
如果 HTML是下图
那就是要获取sorce 里的 src 属性值
属性值配置信息
其中 获取video的地址,我这边是通过XPath获取的。
而属性值,就是上边说的src属性值需要填写的。
文本值
我这边统一用XPath,方便许多
如何用谷歌获取页面的XPath
可以通过谷歌游览器的快捷键F12 或者 右键 检查页面元素
就可以通过1的操作来选择页面上的位置,2的地方下边就会出现元素的范围。
然后,通过,选择的元素,右键,复制XPath 或者 Full XPath 就可以获取得到了。
实现视频地址打开在另外一个页面
这个操作,我是通过新建标签页来的,需要注意的应该是这个变量。
https:{{variables@videoUrl}}
所以,变量的引用方式就是 {{ }} 里包含了 variables@变量名 就可以了
实现视频下载到本地(重命名为指定名称)
可以看到两个地方都用了变量名。
当前逻辑导出导入
可以直接保存为 XXX.json,然后,导入 Automa 工作流即可,甚是方便。
{"extVersion":"1.15.1","name":"抖音视频爬取","icon":"riGlobalLine","table":[],"version":"1.15.1","drawflow":{"nodes":[{"computedPosition":{"x":55,"y":138,"z":0},"data":{"disableBlock":false,"description":"","type":"manual","interval":60,"delay":5,"date":"","time":"00:00","url":"","shortcut":"","activeInInput":false,"isUrlRegex":false,"days":[],"contextMenuName":"自动快进和下一集","contextTypes":[],"observeElement":{"selector":"","baseSelector":"","matchPattern":"","targetOptions":{"subtree":false,"childList":true,"attributes":false,"attributeFilter":[],"characterData":false},"baseElOptions":{"subtree":false,"childList":true,"attributes":false,"attributeFilter":[],"characterData":false}}},"dimensions":{"width":192,"height":72},"handleBounds":{"source":[{"id":"lR7WNj21Qcz0R8vsWyRSQ-output-1","position":"right","x":196.000022148581,"y":27.999978124446006,"width":16,"height":16}]},"id":"lR7WNj21Qcz0R8vsWyRSQ","label":"trigger","position":{"x":55,"y":138},"selected":false,"type":"BlockBasic"},{"computedPosition":{"x":315,"y":135,"z":0},"data":{"active":true,"customUserAgent":false,"description":"","disableBlock":false,"inGroup":false,"updatePrevTab":false,"url":"https://www.douyin.com/","userAgent":"","waitTabLoaded":false},"dimensions":{"width":192,"height":72},"handleBounds":{"source":[{"id":"by31yqg-output-1","position":"right","x":196.000022148581,"y":28.0000131799378,"width":16,"height":16}],"target":[{"id":"by31yqg-input-1","position":"left","x":-19.999999398386485,"y":28.0000131799378,"width":16,"height":16}]},"id":"by31yqg","label":"new-tab","position":{"x":315,"y":135},"selected":false,"type":"BlockBasic"},{"computedPosition":{"x":645,"y":60,"z":0},"data":{"addExtraRow":false,"assignVariable":true,"attributeName":"src","dataColumn":"KGhha","description":"获取video的地址","disableBlock":false,"extraRowDataColumn":"","extraRowValue":"","findBy":"xpath","markEl":false,"multiple":false,"saveData":false,"selector":"/html/body/div[1]/div/div[2]/div[3]/div/div[1]/div[1]/div/div[1]/div/div/xg-video-container/video/source[3]","variableName":"videoUrl","waitForSelector":true,"waitSelectorTimeout":5000},"dimensions":{"width":192,"height":72},"handleBounds":{"source":[{"id":"wfktfdz-output-1","position":"right","x":196.000022148581,"y":28.0000131799378,"width":16,"height":16}],"target":[{"id":"wfktfdz-input-1","position":"left","x":-20.000069509370068,"y":28.0000131799378,"width":16,"height":16}]},"id":"wfktfdz","label":"attribute-value","position":{"x":645,"y":60},"selected":false,"type":"BlockBasic"},{"computedPosition":{"x":990,"y":75,"z":0},"data":{"active":true,"customUserAgent":false,"description":"打开获取的抖音视频,无水印","disableBlock":false,"inGroup":false,"updatePrevTab":false,"url":"https:{{variables@videoUrl}}","userAgent":"","waitTabLoaded":false},"dimensions":{"width":192,"height":72},"handleBounds":{"source":[{"id":"xbgtpyj-output-1","position":"right","x":196.000022148581,"y":28.0000131799378,"width":16,"height":16}],"target":[{"id":"xbgtpyj-input-1","position":"left","x":-19.999859176419324,"y":28.0000131799378,"width":16,"height":16}]},"id":"xbgtpyj","label":"new-tab","position":{"x":990,"y":75},"selected":false,"type":"BlockBasic"},{"computedPosition":{"x":990,"y":180,"z":0},"data":{"disableBlock":false,"description":"保存抖音视频到本地","findBy":"cssSelector","waitForSelector":false,"waitSelectorTimeout":5000,"selector":"","markEl":false,"multiple":false,"type":"url","url":"https:{{variables@videoUrl}}","filename":"{{variables@videoName}}.mp4","onConflict":"uniquify"},"dimensions":{"width":192,"height":72},"handleBounds":{"source":[{"id":"xv4nu27-output-1","position":"right","x":196.000022148581,"y":28.0000131799378,"width":16,"height":16}],"target":[{"id":"xv4nu27-input-1","position":"left","x":-19.999859176419324,"y":28.0000131799378,"width":16,"height":16}]},"id":"xv4nu27","label":"save-assets","position":{"x":990,"y":180},"selected":false,"type":"BlockBasic"},{"type":"BlockBasic","dimensions":{"width":192,"height":72},"handleBounds":{"source":[{"id":"1ouzb51-output-1","position":"right","x":196.000022148581,"y":28.0000131799378,"width":16,"height":16}],"target":[{"id":"1ouzb51-input-1","position":"left","x":-20.000069509370068,"y":28.0000131799378,"width":16,"height":16}]},"computedPosition":{"x":645,"y":165,"z":0},"position":{"x":645,"y":165},"label":"get-text","data":{"disableBlock":false,"description":"获取video的名称","findBy":"xpath","waitForSelector":true,"waitSelectorTimeout":5000,"selector":"/html/body/div[1]/div/div[2]/div[3]/div/div[1]/div[2]/div/div[1]/div/div/div[3]/div[1]/div[2]/div/div/span/span[1]/span/span/span","markEl":false,"multiple":false,"regex":"","prefixText":"","suffixText":"","regexExp":["g","g","g","g"],"dataColumn":"","saveData":false,"includeTags":false,"addExtraRow":false,"assignVariable":true,"variableName":"videoName","extraRowValue":"","extraRowDataColumn":""},"id":"1ouzb51","selected":false}],"edges":[{"id":"vueflow__edge-lR7WNj21Qcz0R8vsWyRSQlR7WNj21Qcz0R8vsWyRSQ-output-1-by31yqgby31yqg-input-1","class":"source-lR7WNj21Qcz0R8vsWyRSQ-output-1 target-by31yqg-input-1","markerEnd":"arrowclosed","selectable":true,"source":"lR7WNj21Qcz0R8vsWyRSQ","sourceHandle":"lR7WNj21Qcz0R8vsWyRSQ-output-1","sourceX":0,"sourceY":0,"target":"by31yqg","targetHandle":"by31yqg-input-1","targetX":0,"targetY":0,"type":"default","updatable":true,"z":0},{"id":"vueflow__edge-12fef6s12fef6s-output-1-wfktfdzwfktfdz-input-1","class":"source-12fef6s-output-1 target-wfktfdz-input-1","markerEnd":"arrowclosed","selectable":true,"selected":false,"source":"by31yqg","sourceHandle":"by31yqg-output-1","sourceX":0,"sourceY":0,"target":"wfktfdz","targetHandle":"wfktfdz-input-1","targetX":0,"targetY":0,"type":"default","updatable":true,"z":0},{"id":"vueflow__edge-wfktfdzwfktfdz-output-1-xv4nu27xv4nu27-input-1","class":"source-wfktfdz-output-1 target-xv4nu27-input-1","markerEnd":"arrowclosed","selectable":true,"selected":false,"source":"1ouzb51","sourceHandle":"1ouzb51-output-1","sourceX":0,"sourceY":0,"target":"xv4nu27","targetHandle":"xv4nu27-input-1","targetX":0,"targetY":0,"type":"default","updatable":true,"z":0},{"id":"vueflow__edge-b3wujz4b3wujz4-output-1-xbgtpyjxbgtpyj-input-1","class":"source-b3wujz4-output-1 target-xbgtpyj-input-1","markerEnd":"arrowclosed","selectable":true,"source":"1ouzb51","sourceHandle":"1ouzb51-output-1","sourceX":0,"sourceY":0,"target":"xbgtpyj","targetHandle":"xbgtpyj-input-1","targetX":0,"targetY":0,"type":"default","updatable":true,"z":0,"selected":false},{"id":"vueflow__edge-by31yqgby31yqg-output-1-1ouzb511ouzb51-input-1","source":"by31yqg","sourceHandle":"by31yqg-output-1","target":"1ouzb51","targetHandle":"1ouzb51-input-1","class":"source-by31yqg-output-1 target-1ouzb51-input-1","updatable":true,"selectable":true,"type":"default","markerEnd":"arrowclosed","z":0,"sourceX":0,"sourceY":0,"targetX":0,"targetY":0}],"position":[95.10493730397354,250.24916845541705],"zoom":0.8705505632961241},"settings":{"blockDelay":0,"debugMode":false,"defaultColumnName":"column","executedBlockOnWeb":false,"inputAutocomplete":true,"insertDefaultColumn":false,"notification":true,"onError":"stop-workflow","publicId":"","restartTimes":3,"reuseLastState":false,"saveLog":true,"tabLoadTimeout":30000},"globalData":"{nt"key": "value"n}","description":"刷新当前抖音视频,获取视频地址","includedWorkflows":{}}
运行结果
总结
不得不说,曾经我就想用JS实现爬虫,这样才是最完美的方案,不曾想,几何时,大佬就已经完备了。
Automa 软件本身十分的优秀,有很多可能性,对于普通人来讲,有如神助!
文档参考地址
https://docs.automa.site/
阅
一键三连呦!,感谢大佬的支持,您的支持就是我的动力!