Nima Ghorab
Nima Ghorab

Reputation: 309

How to open up browser after login with MechanicalSoup and Python script?

I write a Python script with the help of MechanicalSoup to automate a login task. The script successfully runs and I can see that get_url() method returns a url which tells login is successful. At the end, I want to open up a browser (Google Chrome in my case) at the page after login happened but the problem is that I need again enter username and password via Chrome itself!

Is there any solution for this?

Thanks in advance!

Upvotes: 0

Views: 829

Answers (2)

abhishek nandy
abhishek nandy

Reputation: 1

also you can use this >>

import mechanicalsoup as mch

browser = mch.StatefulBrowser()

## your code here to login to website

browser.launch_browser()

Upvotes: 0

yasin lachini
yasin lachini

Reputation: 6036

you should use selenium Forexample for login instagram by firefox the python code is

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("https://www.instagram.com/")
#######################################################################################
emailOrPhone=driver.find_element_by_name("emailOrPhone")
fullName = driver.find_element_by_name("fullName")
username=driver.find_element_by_name("username")
password=driver.find_element_by_name("password")
login_btn = driver.find_element_by_xpath('//*[@class="_0mzm- sqdOP  L3NKy       "]')
#######################################################################################
emailOrPhone.send_keys('[email protected]')
fullName.send_keys("somayeteymuri")
username.send_keys("yusf4ty72")
password.send_keys("1752s1353")
login_btn.click()
########################################################################################

Upvotes: 0

Related Questions