Linux 运行selenium

 

1、进入google-chrome官网下载chrome安装包                        

    官网地址:https://www.google.cn/chrome/

    选择要下载的安装包

 

 2、安装Chrome

rpm -ivh google-chrome-stable_current_x86_64.rpm

 如果报错如下信心:

 

error: Failed dependencies:
	liberation-fonts is needed by google-chrome-stable-87.0.4280.88-1.x86_64
	libvulkan.so.1()(64bit) is needed by google-chrome-stable-87.0.4280.88-1.x86_64

  则:

yum install liberation-fonts libvulkan.so.1*

 3、安装成功

 4、安装 selenium

下载python3源码

wget https://www.python.org/ftp/python/3.7.5/Python-3.7.5.tgz

tar  xf Python-3.7.5.tgz ./
cd Python-3.7.5
编译

./configure --prefix=/usr/local/python3
make&& make install

ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

pip3 install selenium
pip3 install helium

5、下载chrome dirver,然后放置到/usr/bin的目录下

http://chromedriver.storage.googleapis.com/index.html

6、运行demo

#conding=utf-8
from selenium import webdriver
from helium import *


option = webdriver.ChromeOptions()
#option.add_argument('headless')
option.add_argument('no-sandbox')
option.add_argument('disable-dev-shm-usage')
option.add_experimental_option('useAutomationExtension', False)
option.add_experimental_option('excludeSwitches', ['enable-automation'])
browser = webdriver.Chrome(chrome_options=option)

browser.get('http://www.baidu.com/')
print(browser.title)
set_driver(browser)
browser.quit()

  

 

posted @ 2020-12-22 13:59  RoyFans  阅读(3019)  评论(0编辑  收藏  举报