0

I'm using Selenium with Firefox to drive the browser via Python script.

I need to access my Instagram account and, at the moment, I'm using the following code to connect:

class Insta:
    def __init__(self, username, pw, text):
        self.driver = webdriver.Firefox()
        self.driver.get("http://instagram.com")
        sleep(2)
        #click ok on cookies
        self.driver.find_element_by_xpath("/html/body/div[2]/div/div/div/div[2]/button[1]").click()
        sleep(1)
        self.driver.find_element_by_xpath("//input[@name=\"username\"]").send_keys(username)
        self.driver.find_element_by_xpath("//input[@name=\"password\"]").send_keys(pw)
        self.driver.find_element_by_xpath('//button[@type="submit"]').click()

The problem is every time I run the script it has to log in with the credentials.

I would like to know if there's a way to save or store the session information, as it happens when you click the "stay online" box on several websites so, after the very first time where I've to add the credentials, the following execution of the scripts don't need to iterate the process of login because the new session is already logged in the account

Thanks

NicoCaldo
  • 1,171
  • 13
  • 25

1 Answers1

0

The solution was to create a profile into Mozilla, log in with my credentials and load the profile with the Selenium driver using the function webdriver.Firefox() with parameters as below

binary = FirefoxBinary("<--your firefox binary path-->")
profile = FirefoxProfile("<--your firefox profile path-->")

driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary)

Paths can be found in firefox by clicking the top right corner where there's the three lines icon, help, troubleshooting information and you can find Application Binary and Profile Directory

NicoCaldo
  • 1,171
  • 13
  • 25