使用python选择动态填充的下拉列表

发布于 12-28 15:29 字数 492 浏览 1 评论 0原文

我正在使用 mechanize 在网站上填写表单,现在我遇到了动态填充的问题依赖于先前选择的下拉列表。我的表单中有四个动态填充的下拉列表,然后用户可以提交表单。

下拉菜单是:

  Continent                               
    -- Country                               #depends on continent
         -- state                                  #depends on Country
               --city                                      #depends on state

如何使用 python 从这些下拉菜单中选择值?

I'm using mechanize to fill form on a website and now I run into a problem with dynamically-filled drop-down lists that are dependent on a previous selection.I have four drop-downs in a form which are dynamically populated and then user can submit the form.

Drop-down are :

  Continent                               
    -- Country                               #depends on continent
         -- state                                  #depends on Country
               --city                                      #depends on state

How can I select values from these drop-downs using python?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

空‖城人不在2025-01-04 15:29:09

如果值是动态填充的,则无法执行此操作,因为 mechanize 不会负责运行 javascript 代码,因为在 Web 浏览器中显示页面时会发生这种情况。

您有一些替代方案:

  • 使用表单中的值发送 POST 请求,以模拟它已正确填写。
  • 使用 selenium 或 Windmill 之类的东西来驱动真正的 Web 浏览器,该浏览器执行填充下拉小部件所需的 javascript 代码。

If values are dynamically filled, you can't do that since mechanize won't take care of runnig the javascript code as it will happen when displaying the page in a web browser.

You have some alternatives:

  • Send the POST request with the values from the form to simulate that it's been properly filled.
  • Use something like selenium or windmill to drive a real web browser that executes the javascript code that you need to populate the drow-down widgets.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文