Reputation: 19
I would like to fill in and submit a form on a web page using python.
This form:
<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.
Upvotes: 1
Views: 2729
Reputation: 25579
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.
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()
Upvotes: 2