如何在webview任务元素上发送JavaScript或jquery命令? [英] How send JavaScript or jquery commands on webview tasker elements?

查看:104
本文介绍了如何在webview任务元素上发送JavaScript或jquery命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  1. 我创建了一个场景和webview1元素:

  1. I created a scene and webview1 element with:


  • 模式:url

  • 来源:www.google.com


现在,我想创建一个JavaScript任务发送到Webview:

Now, I want to create a JavaScript task to send to the Webview:


  • $(#q)。val(查克诺里斯);

  • $(按钮#search)。click();

PS:我不想只执行Javascript,我想执行它打开的Webview。

PS: I don't want to just execute Javascript, I want to execute it in the opened Webview.

推荐答案

我真的不明白创建webview场景并采取行动的可能性是什么时候你需要什么可以默默地实现。您可以查询网页并遍历其DOM结构,甚至无需查看。

I do not really understand what would possibly be the point of creating webview scenes and acting on them, when what you need can be achieved "silently". You can query webpages and traverse their DOM structure without even viewing.

Tasker支持JavaScript并加载外部库。看看这里有更详细的解释:tasker.wikidot.com/userguide-en:javascript

Tasker does support JavaScript and loading external libraries. Have a look here for more detailed explanation: tasker.wikidot.com/userguide-en:javascript

或者,你可以给SL4A一个go:code.google.com/ p / android-scripting /

Alternatively, you can give SL4A a go: code.google.com/p/android-scripting/

您是否尝试过向WebView属性上的Page Loaded事件添加操作(Javascript或SL4A)?

Have you tried adding an action (either Javascript or SL4A) to the Page Loaded event on WebView properties?

//编辑

@fredericoallan

@fredericoallan

您需要做什么/使用的是使用 HTTP GET HTTP POST 来发送标题和处理会话(我建议任务者插件: RESTask ,因为它允许发送标头)。但首先要做的事情。

What you need to do/use is to play with HTTP GETand HTTP POST for sending headers and handling sessions (I do recommend tasker plugin: RESTask for that as it allows sending headers). But first things first.

为了能够发送标题和设置会话,你需要找到当您打开页面和/或单击 login 按钮时,将发送哪些标题和cookie。要查看(如果您使用的是chrome),您可以使用chrome的内置开发人员工具。只需右键单击页面上的某个位置,然后选择检查元素。
在显示的窗口中,转到标签网络

To be able to send headers and set session, you need to find out what headers and cookies are being sent when you open the page and/or click login button. To see that (if you're using chrome) you can use chrome's built in developer tools. Just right click somewhere on the page and select "inspect element". In the window that'll appear, go to tab "network"

刷新页面并观察网络选项卡。列表上的第一个请求应为 GET 方法,并键入 text / html 。点击它。在右侧窗格中选择标题标签。您现在应该注意到,我们的会话ID存储在 PHPSESSID 下的cookie中。我们以后会需要这些信息

Just refresh the page and observe the network tab. First request on the list should be GET method and type text/html. Click it. Select headers tab in the right pane. You should now notice, that our session ID is being stored in a cookie under PHPSESSID. We're gonna need that information later

为了能够登录,你需要有打开会话,否则服务器将拒绝您访问。
我们已经检查了会话密钥的存储方式和位置,因此我们可以查看登录标头(我们需要知道您的用户名和密码是如何发送到服务器的)。

To be able to log in, you need to have an open session, otherwise server will deny you access. We've checked how and where session key is stored, so we can have a look at log-in headers (we need to know how your username and passord are being sent to the server).

如果开发人员工具仍处于打开状态,请单击 login 按钮。 网络标签的内容应该已更改。对我们来说有趣的是发送的第一个请求( index.php?act = login ,方法 POST ,输入 text / html的)。点击后,我们应该看到远程地址,请求URL,请求方法以及表单数据下面的内容,包含用户名,密码,提交属性。

Having developer tools still open, click login button. Content of the network tab should have changed. What is interesting for us, is the first request sent ( index.php?act=login, method POST, type text/html). When clicked, we should see things like remote address, request URL, request method and little bit down below Form Data containing username, password, submit attributes.

现在,我们已经收集了所有这些信息,我们可以继续构建一个将我们登录的任务。 / p>

Now, having gathered all that information, we can proceed to building a task, that will log us in.


  1. 创建HTTP GET操作(没有其他参数/​​标题)指向 redmine.demo.org 。在服务器响应中,您将收到要设置的HTML标记,标题和cookie。

  2. 从cookie中提取%sessionID(使用变量搜索和替换或变量部分)

  3. 创建指向的HTTP POST操作https://www.untergrund.net/index.php?act=loginpost ,标题为: Cookie =%sessionID 和参数: username =%userid password =%pass PHPSESSID =%sessionID

  1. create HTTP GET action (with no additional parameters/headers) pointing to redmine.demo.org. In a server response you'll receive the HTML markup, headers and cookie to be set.
  2. extract %sessionID from the cookie (using variable search and replace or variable section)
  3. create HTTP POST action pointing to https://www.untergrund.net/index.php?act=loginpost with a header: Cookie=%sessionID and parameters: username=%userid, password=%pass, PHPSESSID=%sessionID

您现在已登录。收到的回复将包含登录时显示的页面。

you are now logged in. Response received will contain page that is diplayed upon login.

HTTP loggin in (119)
A1: RESTask [ Configuration:REST call Package:com.freehaha.restask Name:RESTask Timeout (Seconds):30 ] 
A2: Test Variable [ Type:Length Data:%rthdr_set_cookie Store Result In:%sesslen ] 
A3: Variable Section [ Name:%rthdr_set_cookie From:1 Length:%sesslen-8 Adapt To Fit:Off Store Result In:%sessionID ] 
A4: RESTask [ Configuration:REST call Package:com.freehaha.restask Name:RESTask Timeout (Seconds):30 ] 

这篇关于如何在webview任务元素上发送JavaScript或jquery命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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