自动按a";提交;使用python的按钮
我使用的公交公司经营着一个糟糕的网站(,),它让一个简单的“今天从a到B的时刻表”查询变成了一场噩梦。我怀疑他们是在鼓励使用昂贵的短信查询系统 我正试图从网站上获取整个时间表,通过提交每个可能点到每个可能点的查询,总计大约10k个查询。查询结果将显示在弹出窗口中。我对web编程相当陌生,但熟悉python的基本方面自动按a";提交;使用python的按钮,python,scripting,form-submit,data-harvest,Python,Scripting,Form Submit,Data Harvest,我使用的公交公司经营着一个糟糕的网站(,),它让一个简单的“今天从a到B的时刻表”查询变成了一场噩梦。我怀疑他们是在鼓励使用昂贵的短信查询系统 我正试图从网站上获取整个时间表,通过提交每个可能点到每个可能点的查询,总计大约10k个查询。查询结果将显示在弹出窗口中。我对web编程相当陌生,但熟悉python的基本方面 解析页面、从下拉菜单中选择值并使用脚本按“提交”最优雅的方式是什么 如何将新弹出窗口的内容作为输入提供给程序 谢谢 是一种用于Web浏览的简单脚本语言。这正好是一项运动 斜纹布本质上
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')
我建议你使用。下面是他们页面中的一段代码片段,展示了如何提交表单:
import re
from mechanize import Browser
br = Browser()
br.open("http://www.example.com/")
# follow second link with element text matching regular expression
response1 = br.follow_link(text_regex=r"cheese\s*shop", nr=1)
assert br.viewing_html()
print br.title()
print response1.geturl()
print response1.info() # headers
print response1.read() # body
response1.close() # (shown for clarity; in fact Browser does this for you)
br.select_form(name="order")
# Browser passes through unknown attributes (including methods)
# to the selected HTMLForm (from ClientForm).
br["cheeses"] = ["mozzarella", "caerphilly"] # (the method here is __setitem__)
response2 = br.submit() # submit current form
# print currently selected form (don't call .submit() on this, use br.submit())
print br.form
您很少希望实际“按提交按钮”,而不是直接向处理程序资源发出GET或POST请求。查看表单所在的HTML,查看表单提交到哪个URL的参数,以及它是GET还是POST方法。您可以很容易地使用urllib(2)形成这些请求。mechanize包可以让您避免“查看提交的参数…”这类枯燥的细节。Twill采用mechanize并提供更高级别的抽象。由于错误,我需要使用submit()not submit('0'):HiddenControl实例没有属性“\u click”。请参阅:lists.ydell.org/pipermail/twill/2006-August/000526.html