linux下使用selenium
安装chromedriver
1、安装chrome
用下面的命令安装最新的 Google Chrome
yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
也可以下载到本地再安装
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
yum install ./google-chrome-stable_current_x86_64.rpm
安装必要的库
yum install mesa-libOSMesa-devel gnu-free-sans-fonts wqy-zenhei-fonts
2、安装 chromedriver
查看谷歌浏览器版本
(base) [root@brady ~]# google-chrome --version
Google Chrome 78.0.3904.108
chrome官网 wget https://chromedriver.storage.googleapis.com/2.38/chromedriver_linux64.zip
淘宝源(推荐)wgethttp://npm.taobao.org/mirrors/chromedriver/2.41/chromedriver_linux64.zip
将下载的文件解压,放在如下位置
unzip chromedriver_linux64.zip
/usr/bin/chromedriver
给予执行权限
chmod +x /usr/bin/chromedriver
还可以参考这篇文章,虽然没试过,但感觉很牛逼
https://intoli.com/blog/installing-google-chrome-on-centos/
解决selenium报错--unknown error: DevToolsActivePort file doesn't exist
早上在linux下用selenium启动Chrome时出现问题:
报错:
Traceback (most recent call last):
File "get2.py", line 62, in <module>
browser = webdriver.Chrome()
File "/root/.pyenv/versions/anaconda3-5.1.0/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 75, in __init__
desired_capabilities=desired_capabilities)
File "/root/.pyenv/versions/anaconda3-5.1.0/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/root/.pyenv/versions/anaconda3-5.1.0/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/root/.pyenv/versions/anaconda3-5.1.0/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute
self.error_handler.check_response(response)
File "/root/.pyenv/versions/anaconda3-5.1.0/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.9.0-6-amd64 x86_64)
解决方案:
加上代码:
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--headless')
browser = webdriver.Chrome(chrome_options=chrome_options)
其中
“–no-sandbox”参数是让Chrome在root权限下跑
“–headless”参数是不用打开图形界面
可以额外加这些参数获得更好体验
chrome_options.add_argument('blink-settings=imagesEnabled=false')
chrome_options.add_argument('--disable-gpu')
linux下使用selenium的更多相关文章
- linux环境下安装selenium+chrom+chromdriver.exe
原文:https://blog.csdn.net/yoyocat915/article/details/80580066 原文:https://blog.csdn.net/hanxue6898/art ...
- Ubuntu下的Selenium爬虫的配置
在服务器Ubuntu系统上跑爬虫,爬虫是基于Selenium写的,遇到好几个问题,现在这里记录一下. 1. 安装环境 阿里云,Ubuntu16.04,因为没有界面,所以远程命令行操作.爬虫是基于Sel ...
- linux下无法启动webdriver问题
linux下无法启动webdriver问题: 查看是否有足够多的webdriver进程: ps -ef | grep chromedriver kill -9 `ps -ef |grepchromed ...
- Linux下的Jenkins作为hub,Windows作为node节点,在Android手机上执行自动化脚本
1.在Linux上放selenium-server-standalone-2.53.0.jar,在jar包目录下执行命令java -jar selenium-server-standalone-2.5 ...
- python下的selenium和chrome driver的安装
selenium是一款支持多种语言.多种浏览器.多个平台的开源web自动化测试软件,测试人员可用python.java等语言编写自动化脚本,使得浏览器可以完全按照你的指令运行,大大节省了测试人员用鼠标 ...
- NodeJs在Linux下使用的各种问题
环境:ubuntu16.04 ubuntu中安装NodeJs 通过apt-get命令安装后发现只能使用nodejs,而没有node命令 如果想避免这种情况请看下面连接的这种安装方式: 拓展见:Linu ...
- Linux下服务器端开发流程及相关工具介绍(C++)
去年刚毕业来公司后,做为新人,发现很多东西都没有文档,各种工具和地址都是口口相传的,而且很多时候都是不知道有哪些工具可以使用,所以当时就想把自己接触到的这些东西记录下来,为后来者提供参考,相当于一个路 ...
- Linux下Nodejs安装(完整详细)
之前安装过windows下以及Mac下的node,感觉还是很方便的,不成想今天安装linux下的坑了老半天,特此记录. 首先去官网下载代码,这里一定要注意安装分两种,一种是Source Code源码, ...
- (转载)linux下各个文件夹的作用
linux下的文件结构,看看每个文件夹都是干吗用的/bin 二进制可执行命令 /dev 设备特殊文件 /etc 系统管理和配置文件 /etc/rc.d 启动的配置文件和脚本 /home 用户主目录的基 ...
随机推荐
- HDU5050:Divided Land(大数的进制转化与GCD)
题意:给定大数A和B,求gcd.所有数字都是二进制. 思路:先输入字符串,再转化为大数,然后用大数的gcd函数,最后转化为字符串输出. 利用字符串和大数转化的时候可以声明进制,就很舒服的完成了进制转化 ...
- poi基本使用
poi基本使用 依赖 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi< ...
- JDOJ 1162 是否闰年
1162: 是否闰年 https://neooj.com:8082/oldoj/problem.php?id=1162 题目描述 输入一个年份year,求year是否是闰年,如果是闰年输出L,否则输出 ...
- Excel-信息函数&数组公式
1.IS系列函数-逻辑函数 is函数是一个逻辑函数,可以用来判断一些特定的内容 Istext判断单元格是否是文本 Isnumber判断单元格是否为数值 Istext和isnumber的判断的结果相反 ...
- <DFS & BFS> 130 127
130. Surrounded Regions BFS: 把所有边界上的O先换成A(标记),再深度遍历周围的点. 最后把O换成X(表示不符合要求),所有的A换回O class Solution { p ...
- appium--解决中文输入不了的问题
配置 from appium import webdriver desired_caps={} desired_caps['platformName']='Android' #模拟器 desired_ ...
- Hello 2019 F 莫比乌斯反演 + bitset
https://codeforces.com/contest/1097/problem/F 题意 有n个多重集,q次询问,4种询问 1. 将第x个多重集置为v 2. 将第y和z多重集进行并操作,并赋值 ...
- NOI 2019 退役记
非常抱歉,因为不退役了,所以这篇退役记鸽了.
- JAVA基础系列:Arrays.binarySearch二分查找
首先,binarySearch方法为二分法查找,所以数组必须是有序的或者是用sort()方法排序之后的 1) binarySearch(Object[] a, Object key) a: 要搜索的 ...
- Java开发:字符串切割split函数——切割符转码注意事项
一.问题如下: 1.先对一个已有字符串进行操作,使用 ; 进行分割: //示例字符串 String string="sr1.db1.tb1.df1;sr2.db2.tb2.d ...