Open page in secret mode by specifying browser language with Selenium Python Bindings (Chrome)

"There is only a GUI via a web browser." When I was looking for ways to automate the construction of MW, I did not find it immediately when I searched for it, so I made a note.

$ pip install selenium
$ brew install chromedriver

sample.py


# -*- coding: utf-8 -*-
from __future__ import division, print_function, absolute_import, unicode_literals

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

options = webdriver.ChromeOptions()
options.add_argument('--incognito')  # secret mode
options.add_experimental_option('prefs', {'intl.accept_languages': 'en_US'}) # locale=en_US

# use local driver
driver = webdriver.Chrome(chrome_options=options)

## use remote driver
#driver = webdriver.Remote(
#    command_executor='http://127.0.0.1:4444/wd/hub',
#    desired_capabilities=options.to_capabilities())

driver.get("https://www.debian.org/")
assert "Debian" in driver.title
elem = driver.find_element_by_name("P")
elem.clear()
elem.send_keys("debi_fujin")
elem.send_keys(Keys.RETURN)
assert "No results found." not in driver.page_source
driver.close()

When executed, it looks like this.

$ python sample.py

6月-17-2017 22-48-19.gif

As a point of addiction

It is around.

Reference: [Selenium] How to set Accept \ -Language header with python \ + ChromeDriver -miyajan blog

Recommended Posts

Open page in secret mode by specifying browser language with Selenium Python Bindings (Chrome)
How to switch to smartphone mode with Python + Selenium + Chrome
Scraping with selenium in Python
Scraping with Selenium in Python
Scraping with Selenium in Python (Basic)
Open UTF-8 with BOM in Python
[Python] Get elements by specifying attributes with prefix search in BeautifulSoup
Download the file by specifying the download destination with Python & Selemiun & Chrome (Windows version)
Display Python 3 in the browser with MAMP
[Python] Automatically operate the browser with Selenium
Automatic operation of Chrome with Python + Selenium + pandas
Try running Google Chrome with Python and Selenium
Log in to Yahoo Business with Selenium Python
Create a new page in confluence with Python
Log in by passing the login session cookie obtained by Python requests to the Selenium browser.
[Selenium] Open the link in a new tab and move it [Python / Chrome Driver]
Note the frequently used options in Python + Selenium + Chrome
Use FireFox (via Homebrew-cask) with Selenium WebDriver Python bindings
How to download files from Selenium in Python in Chrome
JPEG image generation by specifying quality with Python + OpenCV
Automate Chrome with Python and Selenium on your Chromebook
I can't manipulate iframes in a page with Selenium
[Python] Delete by specifying a tag with Beautiful Soup