Skip to main content
 首页 » 编程设计

python之使用 python 自动按下 "submit"按钮

2025年05月04日14telwanggs

我使用的公交公司运营着一个糟糕的网站(Hebrew、English),这使得简单的“今天从 A 到 B 的时间表”查询成为一场噩梦。我怀疑他们试图鼓励使用昂贵的 SMS 查询系统。

我正在尝试通过将每个可能点的查询提交到每个可能点的查询来从站点获取整个时间表,这将总计大约 10k 个查询。查询结果出现在弹出窗口中。我对网络编程很陌生,但熟悉 python 的基本方面。

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

谢谢!

请您参考如下方法:

Twill是一种用于 Web 浏览的简单脚本语言。它恰好是一个 python api .

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).

上述链接文档中“按下”提交的示例:

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')