Python Mechanize 与动态下拉选择
我正在使用 mechanize 来填写表单,并且遇到了动态填充下拉列表的问题取决于先前的选择。
在 mechanize 中,我执行以下操作来选择类别:
import mechanize
br = mechanize.Browser()
"""Select the form and set up the browser"""
br["state"] = ["California"]
br["city"] = ["San Francisco"] # this is where the error is
br.submit()
在选择州“加利福尼亚”之前,我无法选择城市“旧金山”,因为选择“加利福尼亚”后,城市下拉列表会动态填充。
我怎样才能用Python提交城市并实现机械化?
I'm using mechanize to fill forms and I run into a problem with dynamically-filled dropdown lists that are dependent on a previous selection.
In mechanize, I do something like this to select the category:
import mechanize
br = mechanize.Browser()
"""Select the form and set up the browser"""
br["state"] = ["California"]
br["city"] = ["San Francisco"] # this is where the error is
br.submit()
I cannot choose the city as "San Francisco" until I have chosen the state as "California," because the city dropdown list is dynamically populated after choosing "California."
How can I submit the city with Python and mechanize?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
mechanize 不支持 JavaScript。相反,您应该使用 urllib2 发送所需的值。
mechanize doesn't support JavaScript. Instead, you should use urllib2 to send the desired values.