Is it possible to write a Python script for opening a browser and logging into a website? How could you do it?
-
If possible, please suggest some starting points. I have basic knowledge of Python and will be able to follow simple tutorials.
-
Answer:
Yes, it's definitely possible. http://www.seleniumhq.org/ is perfect for what you're trying to do. There's even a http://selenium-python.readthedocs.org/en/latest/ that will let you integrate with browsers like Firefox and Chrome. Here's an example of how you might log into Facebook. from selenium import webdriver from selenium.webdriver.support import ui from selenium.webdriver.common.keys import Keys def page_is_loaded(driver): return driver.find_element_by_tag_name("body") != None driver = webdriver.Firefox() driver.get("https://www.facebook.com/") wait = ui.WebDriverWait(driver, 10) wait.until(page_is_loaded) email_field = driver.find_element_by_id("email") email_field.send_keys("[email protected]") password_field = driver.find_element_by_id("pass") password_field.send_keys("password") password_field.send_keys(Keys.RETURN) With Selenium, you can automate pretty much anything you'd want to do with a web browser. Good luck!
Dan Loewenherz at Quora Visit the source
Other answers
Depending upon what you want to do, you should check out: https://pypi.python.org/pypi/mechanize/ http://www.seleniumhq.org/ http://scrapy.org/doc/
Navin Kabra
Use Selenium Webdriver with python http://www.seleniumhq.org/docs/03_webdriver.jsp. Should do the trick for you
Tarang Mittal
As another guys already said, you can do that with Selenium. Selenium of version 1 was using JavaScript, now there is Selenium 2 which is using webdriver which is API implemented in browsers. With webdriver is action almost same like real user action, so it's much better for using for testing. I will just add one thing: if you want to use webdriver with Python, API is not very good and there is missing a lot of useful methods. So I did package webdriverwrapper, which provides a lot of improvements which can not be used in Selenium, because it just doesn't belong there. But it's still needed. For example filling of forms is much simpler, or you can easily download files, some shortcuts, working with windows/tabs, utilities for testing and more. Check it out: https://github.com/horejsek/python-webdriverwrapper
Michal HoÅejÅ¡ek
I used splinter library in Python to great success. I used the code given in the following blog to do an automated login to my institute's webpage https://pythonadventures.wordpress.com/tag/autologin/
Pavan Rohit
Another quick solution is mechanize lib in python as pointed by import mechanize import cookielib # Browser br = mechanize.Browser() # Cookie Jar cj = cookielib.LWPCookieJar() br.set_cookiejar(cj) # Browser options br.set_handle_equiv(True) #br.set_handle_gzip(True) br.set_handle_redirect(True) br.set_handle_referer(True) br.set_handle_robots(False) br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1) # User-Agent br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')] r = br.open('<website you want to login>') html = r.read() br.select_form(nr=0) br.form['input_name_for_username']=username br.form['input_name_for_password']=password br.submit() # all done!
Hardik Akbari
Related Q & A:
- How long should I give a prof to write a letter of recommendation for a graduate school application?Best solution by Yahoo! Answers
- Is it possible to be a travel nurse when your a single mom of 1 child?Best solution by Yahoo! Answers
- Is it possible to have a tropical rain forest in a green house?Best solution by wikihow.com
- Is it possible to buy a flat screen tv without a tuner?Best solution by Yahoo! Answers
- Would a drop of sweat on a capacitive touchscreen be considered a touch?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.