Home > Backend Development > Python Tutorial > How to install Selenium+Headless Chrome in Python environment

How to install Selenium+Headless Chrome in Python environment

零到壹度
Release: 2018-04-04 10:58:58
Original
6342 people have browsed it


This article mainly introduces how to install Selenium+Headless Chrome in the Python environment. The editor thinks it is quite good. Now I will share it with you and give it as a reference. . Let’s follow the editor to take a look.

I’ve been learning crawlers recently, and I suddenly discovered:

Python 3.6.4 (default, Jan  5 2018, 02:35:40) 
[GCC 7.2.1 20171224] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from selenium import webdriver
>>> driver=webdriver.PhantomJS()
/usr/lib/python3.6/site-packages/selenium/webdriver/phantomjs/webdriver.py:49: UserWarning: Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome or Firefox instead
  warnings.warn('Selenium support for PhantomJS has been deprecated, please use headless '
Copy after login

Simply put, it means that the new version of Selenium no longer supports PhantomJS, please use A headless version of Chrome or Firefox instead. I'm confused...Many tutorials nowadays are based on PhantomJS. There is no way. Since I am using the Chrome browser, I will share the installation method of Headless Chrome.


1. Run cmd or Ctrl + R to enter the command line

How to install Selenium+Headless Chrome in Python environment

##2. Enter python

How to install Selenium+Headless Chrome in Python environment

3. Enter the code block

The code block syntax follows standard markdown code, for example:

from selenium import webdriverfrom selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('http://www.baidu.com')
Copy after login

How to install Selenium+Headless Chrome in Python environment
How to install Selenium+Headless Chrome in Python environment
How to install Selenium+Headless Chrome in Python environment
How to install Selenium+Headless Chrome in Python environment

Okay, Headless Chrome is now installed.

The above is the detailed content of How to install Selenium+Headless Chrome in Python environment. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template