Python提交表单 [英] Python Submit form

查看:63
本文介绍了Python提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用python填写并在网页上提交表单.

I would like to fill in and submit a form on a web page using python.

此表单:

<form method="POST" id="login" action="site/enter.php" >
  <input type="text" placeholder="Login" name="login" class="login" tabindex="1">
  <input type="password" placeholder="Password" name="psw" class="password" tabindex="2">
  <input type="submit" class="btn_auth" value="" title="Enter" tabindex="3">
</form>

但是不能做到.我放置了登录名和密码,但是无法模拟提交"按钮.

But can't do it. I place login and pass, but can't emulate submit button.

推荐答案

使用selenium的Webdriver来驱动网页比使用机械化之类的要容易得多.特别是如果页面是动态创建的.

It's much easier to use selenium's Webdriver to drive webpages than to use something like mechanize. Especially if the page is dynamically created.

您需要安装硒. pip install selenium应该可以工作.您还需要安装Firefox版本.

You'll need to install selenium. pip install selenium should work. You'll also need a version of Firefox installed.

from selenium import webdriver

browser = webdriver.Firefox()
browser.implicitly_wait(5)
browser.get('http://some_url.com')
browser.find_element_by_id('login').send_keys('your_login') 
browser.find_element_by_name('pws').send_keys('your_password')
browser.find_element_by_class_name('btn_auth').click() 

print browser.page_source
browser.close()

这篇关于Python提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆