To the Chrome browser, for example:
method one:
from selenium.webdriver Import Chrome, ChromeOptions opt = ChromeOptions () # Create a Chrome parameter object opt.headless = True # to set Chrome no visual interface mode, windows / Linux Jieke Driver = Chrome (Options = opt) # Create a Chrome-free interface object driver.get ( ' http://www.baidu.com ' )
Print (driver.current_window_handle) Print (driver.page_source) driver.close ()
Method Two:
from selenium.webdriver Import the Chrome from selenium.webdriver.chrome.options Import the Options opt = the Options () opt.add_argument ( ' --no-Sandbox ' ) # solve DevToolsActivePort given file does not exist opt.add_argument ( ' window-size = 1920x3000 ' ) # specify the resolution opt.add_argument ( ' --disable-GPU ' ) # Google documents mentioned the need to add this property to circumvent the bug opt.add_argument ( ' --hide-scrollbars ' ) #Scroll bar is hidden, to deal with some special pages opt.add_argument ( ' Blink-Settings = imagesEnabled = false ' ) # not loaded images, to enhance the speed opt.add_argument ( ' --headless ' ) # browser does not provide a visual interface. If the Linux system does not support this visualization without fail to start
# Opt.binary_location r = "C: \ Program Files (x86) \ Google \ Chrome \ the Application \ chrome.exe" browser manually specify the location #
Driver = Chrome (Options = opt) # create no interface objects
driver.get('http://www.baidu.com')
print(driver.current_window_handle)
print(driver.page_source)
driver.close()