自动化 Chrome [英] Automating Chrome

查看:25
本文介绍了自动化 Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将一些 urlencoded Javascript 粘贴到 Firefox 和 Chrome 上的 URL 时,我看到了一些疯狂的事情.是否可以使用这种技术告诉 Chrome 访问 URL,然后将其保存为文件?我正在尝试自动化 Chrome,而 Selenium 看起来非常令人生畏.

I've seen some wild things happen when I paste some urlencoded Javascript into a URL on Firefox and Chrome. Is it possible to use this technique to tell Chrome to visit a URL and then save it as a file? I'm trying to automate Chrome, and Selenium looked extremely daunting.

编辑:不幸的是,我忘了在这里更清楚.让我解释.wget、curl 等将无法工作,因为我必须在其中一些脚本中登录.我看过 iMacros,但发现我无法让它们从命令行运行,除非在 Windows 上运行,除非我支付 499 美元的包.GCE 的其他一些优点是开发平台在某种程度上是免费和开放的,并且它们是跨平台的.(我使用 Linux.)

EDIT: Unfortunately, I forgot to be more clear here. Let me explain. Things like wget, curl, etc. won't work because I have to get through logins in some of these scripts. And I've looked at iMacros, but found that I can't get them to run from command line except on Windows, unless I pay for the $499 package. Some other advantages of GCEs are that the dev platform is free and open to some degree, and they are cross-platform. (I use Linux.)

编辑:此时,我正在学习 Google Chrome 扩展程序.看起来它们很容易构建并且会让我(我认为)告诉浏览器打开一个新选项卡,转到一个页面,操作该页面上的 DOM(例如填充一些字段并登录),然后操作响应页面上的 DOM.GCE 不允许您执行文件 I/O,因此它们不像带有 XPCOM 的 Firefox 扩展,但是您可以通过使用 AJAX 将数据发送到后端脚本(如 LAMP 服务器上的 PHP 脚本)以保存那个数据.

EDIT: At this point, I'm learning about Google Chrome Extensions. It appears they are easy to build and will let me (I think) tell the browser to open a new tab, go to a page, manipulate the DOM on that page (such as populating some fields and logging in), and then manipulate the DOM on the response page. GCEs don't let you do File I/O, so they are not like Firefox Extensions with XPCOM, but you can get around that by using AJAX to send data to a backend script (like a PHP script on a LAMP server) to save that data.

编辑:顺便说一句,这有点偏离主题(但我补充说明)我提到的 Javascript 中的那些疯狂的东西"是当您操作 DOM 创建一个 URL 时看起来像这样:

EDIT: By the way, and this is slightly off-topic (but I add to clarify) those "wild things" in Javascript that I mentioned were when you manipulate the DOM creating a URL that looks like so:

javascript:(function(){...your URL-encoded Javascript here...})();

推荐答案

解决方案似乎是制作自己的 Google Chrome 扩展程序 (GCE).如果你知道如何做一些稍微高级的 Javascript 东西,它在大约 4 小时内很容易学习,并且非常强大.我可以使用 Tabs API 创建一个新选项卡并转到特定 URL.然后,我可以将 jQuery 注入到该 URL 中并使其操作 DOM 或执行我们通常可以使用 jQuery 执行的任何操作.我无法进行文件 I/O,但有两种解决方法.一,我可以强制浏览器从远程位置下载文件,我可以通过 jQuery 的 $.get() 或 $.post() 调用将数据从当前页面发送回远程服务器.

The solution appears to be to make one's own Google Chrome Extension (GCE). It is easy to learn within about 4 hours if you know how to do slightly advanced Javascript stuff, and is very powerful. I can use the Tabs API to create a new tab and go to a specific URL. I can then inject jQuery into that URL and make it manipulate the DOM or do anything we normally can do with jQuery. I can't do file I/O, but there are two workarounds. One, I can force the browser to download a file from a remote location, and I can send data from the current page back up to a remote server via jQuery's $.get() or $.post() calls.

这篇关于自动化 Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆