1. Using Selenium in Linux 1. Install Chrome Install Google Chrome using the following command You can also download it locally and then install it
Install Necessary Libraries 2. Install chromedriver (the corresponding versions of chrome and chromedriver are attached at the end) chrome official website Taobao source (recommended) Unzip the downloaded file and place it in the following location:
Grant execute permissions 3. Run the code to see if it is successful (under Python)
2. Chrome runs in non-interface mode from selenium import webdriver from selenium.webdriver.chrome.options import Options chrome_options = Options() chrome_options.add_argument('--no-sandbox')#Solve the error that the DevToolsActivePort file does not existchrome_options.add_argument('window-size=1920x3000') #Specify the browser resolutionchrome_options.add_argument('--disable-gpu') #Google documentation mentions that this attribute needs to be added to avoid bugs chrome_options.add_argument('--hide-scrollbars') #Hide scrollbars, for some special pageschrome_options.add_argument('blink-settings=imagesEnabled=false') #Do not load images, increase speedchrome_options.add_argument('--headless') #The browser does not provide visualization pages. If the system does not support visualization under Linux, the startup will fail without this addition#Create browser objectdriver = webdriver.Chrome(executable_path=path, chrome_options=chrome_options)#executable_path: browser driver pathdriver.get(url) 3. Download files in non-interface mode Previously, Chromedriver running in headless mode would not correctly download files due to it sparsely parsing the preferences file provided to it. An engineer from the headless Chrome team suggested using DevTools' "Page.setDownloadBehavior" to fix this issue. This changelist implements this fix. Downloaded files default to the current directory, which can be set using download_dir when instantiating a chromedriver instance. Also added tests to ensure correct download functionality.
The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Native js to implement drop-down menu
>>: Detailed tutorial for downloading, installing and configuring MySQL 5.7.27
Table of contents umask Umask usage principle 1. ...
As shown below: As shown above, just replace it. ...
Sorting query (order by) In e-commerce: We want t...
1. Install Oracle There are too many Oracle insta...
Why is it that when the input tag type is file an...
As the company's influence grows and its prod...
When we make a form, we often set a submit button ...
CentOS 8 is officially released! CentOS fully com...
<br />Question: How to write in HTML to jump...
Table of contents sequence 1. Centralized routing...
The pre element defines preformatted text. Text en...
Table of contents Written in front 1. Ngixn image...
This article shares the specific code for JavaScr...
1. Normal background blur Code: <Style> htm...
Table of contents 1. Sample code 2. See the essen...