Python提交表单

Python提交表单,python,forms,submit,Python,Forms,Submit,我想用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="pass

我想用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>


但我做不到。我放置了登录和传递,但无法模拟提交按钮。

使用selenium的Webdriver来驱动网页比使用mechanize之类的工具容易得多。尤其是在动态创建页面时

您需要安装selenium<代码>pip安装selenium应该可以工作。您还需要安装Firefox版本

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()

什么?如果有的话,您使用的是什么样的web框架?你有什么问题?我们需要更多信息。请发布非工作代码,否则这个问题太模糊了。这看起来像是Selenium Webdriver的工作!cj=cookielib.CookieJar()opener=urllib2.build\u opener(urllib2.HTTPCookieProcessor(cj))urllib2.install\u opener(opener)values=dict(login=username,psw=userpass,frm='submit')data=urllib.urlencode(values)req=urllib2.Request(root\u url,data)home\u page=opener.opener(req)page_text=home_page.read()打印page_text您必须使用类似cURL的东西来发布表单。除非页面使用JavaScript。这是一个过度的问题,因为现在很多web都是用JS呈现的,我觉得最好先去那里。你的Riv哪部分不工作?它只是打开Chrome,什么都不做所以没有stacktrace?我注意到我的代码中有一个额外的空格,我刚刚删除了它?你不是在盲目地复制它,是吗?@aychedee-我收到一条消息
“WebDriver”对象没有“隐式”属性
。那条线应该做什么?不使用它会改变它的工作方式吗?