自动按下“提交"按钮.使用python的按钮 [英] Automatically pressing a "submit" button using python

查看:130
本文介绍了自动按下“提交"按钮.使用python的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的巴士公司经营的网站糟糕透顶(英语),这使得简单的从今天的A到B时间表"成为梦a.我怀疑他们试图鼓励使用昂贵的SMS查询系统.

The bus company I use runs an awful website (Hebrew,English) which making a simple "From A to B timetable today" query a nightmare. I suspect they are trying to encourage the usage of the costly SMS query system.

我正在尝试通过向每个可能的点向每个可能的点提交查询来从站点中获取整个时间表,这将总计约1万个查询.查询结果将显示在弹出窗口中.我是Web编程的新手,但熟悉python的基本方面.

I'm trying to harvest the entire timetable from the site, by submitting the query for every possible point to every possible point, which would sum to about 10k queries. The query result appears in a popup window. I'm quite new to web programming, but familiar with the basic aspects of python.

  1. 解析页面,从下拉菜单中选择一个值并使用脚本按提交"的最优雅方式是什么?
  2. 如何为程序提供新弹出窗口的内容作为输入?

谢谢!

推荐答案

Twill 是一种简单的脚本语言,用于网页浏览.碰巧使用 python api .

Twill is a simple scripting language for Web browsing. It happens to sport a python api.

斜纹布基本上是围绕机械化包装的薄壳.所有斜纹命令都在commands.py文件中实现,并且pyparsing进行解析输入并将其转换为Python命令的工作(请参阅parse.py).交互式shell工作和readline支持通过cmd模块(来自标准Python库)实现.

twill is essentially a thin shell around the mechanize package. All twill commands are implemented in the commands.py file, and pyparsing does the work of parsing the input and converting it into Python commands (see parse.py). Interactive shell work and readline support is implemented via the cmd module (from the standard Python library).

从上述链接文档按"提交的示例:

An example of "pressing" submit from the above linked doc:

from twill.commands import go, showforms, formclear, fv, submit

go('http://issola.caltech.edu/~t/qwsgi/qwsgi-demo.cgi/')
go('./widgets')
showforms()

formclear('1')
fv("1", "name", "test")
fv("1", "password", "testpass")
fv("1", "confirm", "yes")
showforms()

submit('0')

这篇关于自动按下“提交"按钮.使用python的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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