是否有可能回发从客户端自动化? [英] Is it possible to automate postback from the client side?

查看:321
本文介绍了是否有可能回发从客户端自动化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个客户需要从周期性的Web服务拉客户数据。数据本身是作为通过JavaScript回传CSV文件,是服务的网站中大部分的导航。

One of my clients needs to pull customer data from a web service periodically. The data itself is provided as CSV files via javascript postbacks, as is most of the navigation within the service's website.

现在,在整个系统中最严重的瓶颈为人类登录到网页,导航到下载页,并手动下载的文件添加到系统的其余部分的需要。

Right now, the worst bottleneck in the entire system is the need for a human to log into the web page, navigate to the download page, and manually add the downloaded file to the rest of the system.

能否下载经由回传文件的过程进行自动化? (例如说通过可通过cron运行的shell脚本?)

Can the process of downloading files via postback be automated? (Say for example via a shell script that can be run via cron?)

如果是这样,你会推荐为最合适的工具,这样做呢?

If so, what would you recommend as the most appropriate tool for doing so?

推荐答案

在任何情况下,遇到这个问题再说,我已经找到了解决办法:

In case anyone comes across this question again, I've found a solution:

诀窍是使用机械化以及一系列调用到 Browser.submit()上相应的页面。

The trick is to use Mechanize, and a series of calls to Browser.submit() on the appropriate pages.

的模式挂断别人也可能遇到的是ASP.NET页面(基于回发导航的最大来源,在我的经验)也需要被称为一个隐藏的参数 __ EVENTTARGET 的形式,当您使用机械化,这将不存在。

The one hangup that others might also encounter is that ASP.NET pages (the biggest source of postback-based navigation, in my experience) also need a hidden parameter called __EVENTTARGET in the form, which won't exist when you use mechanize.

__ doPostBack('富')在这些网页上的功能通过一个JavaScript给出了相关的值 __ EVENTTARGET 的onclick事件在每个环节,但由于机械化不使用JavaScript,你需要自己设置这些值。

The __doPostBack('foo') function on these pages gives the relevant value to __EVENTTARGET via a javascript onclick event on each of the links, but since mechanize doesn't use javascript you'll need to set these values yourself.

我做了一个小巧的实用功能,以我的脚本中使用,这是否:

I made up a quick little utility function to use within my scripts that does this:

def add_event_target(form, target):
    #Creates a new __EVENTTARGET control and adds the value specified
    #.NET doesn't generate this in mechanize for some reason -- suspect maybe is 
    #normally generated by javascript or some useragent thing?
    form.new_control('hidden','__EVENTTARGET',attrs = dict(name='__EVENTTARGET'))
    form.set_all_readonly(False)
    form["__EVENTTARGET"] = target

我希望这是任何人谁也许都会碰到这个问题以后有帮助的。

I hope this is helpful for anyone who maybe comes across this question later.

这篇关于是否有可能回发从客户端自动化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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