Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use selenium to open chrome browser and keep login mode in python

2025-04-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how python uses selenium to open chrome browser to maintain login mode". The editor shows you the operation process through an actual case, which is simple, fast and practical. I hope this article "how to use python to open chrome browser with selenium to maintain login mode" can help you solve the problem.

Selenium Operation browser

Here we take CSDN as an example to show how to make selenium bring the user's login information when opening the chrome browser.

Open the website of the chrome browser from selenium import webdriverfrom selenium.webdriver import ChromeOptions# setting operation web_url = "https://bbs.csdn.net"browser = webdriver.Chrome (executable_path=r" D:\ chromedriver_win32\ chromedriver\ chromedriver.exe ") # Open the web page browser.get (web_url)

After running the program, open the browser interface as shown above, and you can see that there is no login information for the user by default.

Open a chrome browser with user login information and open a chrome window with user information

"C:\ Program Files (x86)\ Google\ Chrome\ Application\ chrome.exe"-remote-debugging-port=9014-- user-data-dir= "C:\\ Users\ 15053\ AppData\ Local\ Google\ Chrome\\ User Data"

Because chrome is installed in the default installation path, the path is the same as above. If you customize the path during installation, be careful to modify the path of chrome.exe.

The user-data directory is the directory where chrome caches data and contains the user's login information. If you are using it on your own computer, you need to change 15053 to your own user name.

Note: it is recommended that you close the chrome browser when executing the above command, otherwise you may not be able to connect to chrome later when you execute the python program.

Use selenium to open the website from selenium import webdriverfrom selenium.webdriver import ChromeOptionsweb_url = "https://bbs.csdn.net"# loads the account and password saved in cookies options= ChromeOptions () options.add_experimental_option (" debuggerAddress "," 127.0.0.1 chromedriver 9014 ") browser = webdriver.Chrome (executable_path=r" D:\ chromedriver_win32\ chromedriver\ chromedriver.exe ", chrome_options=options) browser.get (web_url)

As you can see, the website opened at this time already contains the user's login information.

This is the end of the content about "how python uses selenium to open chrome browser to maintain login mode". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report