2

I'm a beginner in python and as a learning project i decided to just make a little script to lunch a webpage and log into it. Now after doing lots of googling (got many messy bits and piece of knowlegde) i found out that each website have it own way of handling login requests, and that there was many ways to emulate an instance of a browser to retrieve and post data ( urllib2, selenium, twill and blablabla).

So I know it is possible to log in into a website from python ( for a specific site and using a specific way) but I can't seem to display the logged page in a browser.

Can anyone help me please ?

2
  • 2
    We can't really help you without some code. Please post some, and if at all possible, maake it an SSCCE. Commented Jan 13, 2012 at 4:13
  • It is unclear whether you want to login on an existing webpage or if you want to display a login page. Commented Jan 13, 2012 at 5:15

1 Answer 1

1

I think selenium can do this job.

code snippet:

from selenium import webdriver 
from selenium.common.exceptions import NoSuchElementException 
from selenium.webdriver.common.keys import Keys

browser = webdriver.Firefox() # Get local session of firefox 
browser.get(yoursite) # Load page 
elem = browser.find_element_by_name("email") # Find the query box 
elem.send_keys(email) 

ps = browser.find_element_by_name("password") # Find the query box 
ps.send_keys(passwd + Keys.RETURN)

this piece of code will drive your firefox to open the logged page.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks this is exactly what I was looking for, however this it always open in a new instance of the browser , it is possible to open the web page in a tab instead ?
I'm also learning selenium; I believe there is a way to open a tab, but I don't know how to do it. I am reading the python doc of selenium now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.