简体   繁体   English

Python - 填写并提交HTML表单

[英]Python - Fill and submit a HTML Form

I would like to fill in and submit a form on a web page using python. 我想填写并使用python在网页上提交表单。 The form I want to interact with has several drop down boxes which are filled using JavaScript. 我想要与之交互的表单有几个下拉框,使用JavaScript填充。 I have looked at the mechanize library but it doesn't handle JavaScript. 我查看了mechanize库,但它没有处理JavaScript。 Can you suggest an alternate library/method for interacting with the form? 你能建议一个替代的库/方法来与表单进行交互吗?

Cheers, 干杯,

Pete 皮特

  1. Selenium RC or Windmill (http://www.getwindmill.com/) Selenium RC或Windmill(http://www.getwindmill.com/)

  2. Examine the form's returned GET or POST values; 检查表单返回的GET或POST值; use urllib2 to submit synthesized requests directly. 使用urllib2直接提交合成请求。

The form effectively sends information back to the server (or maybe somewhere else) after you press the submit button. 在您按下提交按钮后,表单有效地将信息发送回服务器(或其他地方)。

I don't know how you would directly interact with the form, but you could just send the information back to the server in the same way as submitting the form would (without actually submitting it or physically pressing on things). 我不知道你将如何直接与表单进行交互,但你可以像提交表单一样将信息发送回服务器(没有实际提交或实际按压事物)。

So for example some forms put the parameters specified in the form (and their values) at the end of the url in the HTTP request once submitting the form. 因此,例如,一些表单在提交表单后将表单中指定的参数(及其值)放在HTTP请求中url的末尾。 Others put the parameters in the body of the HTTP request. 其他人将参数放在HTTP请求的正文中。 In PHP i know that PHP automatically takes these parameters out for you (into a global array). 在PHP中,我知道PHP会自动为您提供这些参数(进入全局数组)。

In this case you would simply put your own version of the parameters (names/values) in the HTTP request, by looking a what names/values there are in the forms source code. 在这种情况下,您只需通过查看表单源代码中的名称/值,将您自己的参数(名称/值)版本放在HTTP请求中。

Although the form may send its information to the server using javascript... 虽然表单可以使用javascript将其信息发送到服务器...

Sorry if that made no sense. 对不起,如果没有意义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM