linux版⽕狐浏览器部署详解
exitedFirefox下载地址
我本地测试⽤的驱动版本:geckodriver-v0.30.0-win64.zip
我本地测试⽤的⽕狐版本:92.0
我本地测试⽤的操作系统:centos7
⽕狐浏览器解压安装出现的问题
下载⽕狐版本包,上传,解压(tar jxf)执⾏命令报错如下:
问题⼀:
[machangwei@xxx ~]$ ./firefox/firefox
XPCOMGlueLoad error for file /home/machangwei/firefox/libmozgtk.so:
libgtk-3.so.0: cannot open shared object file: No such file or directory
Couldn't load XPCOM.
问题⼆:
[deployer@xxx firefox]$ ./firefox
XPCOMGlueLoad error for file /apps/svr/firefox/libxul.so:
libXt.so.6: cannot open shared object file: No such file or directory
Couldn't load XPCOM.
问题复现及解决
问题⼀复现及解决:
问题⼀缺少gtk3,执⾏如下命令解决
yum install -y gtk3
如果还不⾏,把gtk2也装上,回头补充详情
[root@localhost ~]# rpm -qa|egrep "gtk2|gtk3"
gtk2-2.24.31-1.el7.x86_64
gtk3-3.22.30-6.el7.x86_64
[root@localhost ~]# yum remove gtk3
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package gtk3.x86_64 0:3.22.30-6.el7 will be erased
--> Processing Dependency: libgdk-3.so.0()(64bit) for package: google-chrome-stable-88.0.4324.150-1.x86_64
--> Processing Dependency: libgtk-3.so.0()(64bit) for package: google-chrome-stable-88.0.4324.150-1.x86_64
--> Running transaction check
---> Package google-chrome-stable.x86_64 0:88.0.4324.150-1 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=====================================================================================================
Package Arch Version Repository Size
============================================================================================= Removing:
gtk3 x86_64 3.22.30-6.el7 @updates 17 M
Removing for dependencies:
google-chrome-stable x86_64 88.0.4324.150-1 installed 228 M
Transaction Summary
==========================================================
Remove 1 Package (+1 Dependent package)
Installed size: 245 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : google-chrome-stable-88.0.4324.150-1.x86_64 1/2 Erasing : gtk3-3.22.30-6.el7.x86_64 2/2
Verifying : gtk3-3.22.30-6.el7.x86_64 1/2
Verifying : google-chrome-stable-88.0.4324.150-1.x86_64 2/2 Removed:
gtk3.x86_64 0:3.22.30-6.el7 Dependency Removed:
google-chrome-stable.x86_64 0:88.0.4324.150-1
Complete!
[root@localhost ~]# ./firefox/firefox
XPCOMGlueLoad error for file /root/firefox/libmozgtk.so:
libgtk-3.so.0: cannot open shared object file: No such file or directory
Couldn't load XPCOM.
[root@localhost ~]# yum install -y gtk3
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
google-chrome | 1.3 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/4): google-chrome/primary | 1.8 kB 00:00:00
(2/4): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(3/4): epel/x86_64/primary_db | 7.0 MB 00:00:15
(4/4): updates/7/x86_64/primary_db | 12 MB 00:00:29 Determining fastest mirrors
* base: mirrors.aliyun
* extras: mirrors.aliyun
* updates: mirrors.aliyun
google-chrome 3/3
Resolving Dependencies
--> Running transaction check
---> Package gtk3.x86_64 0:3.22.30-6.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
。。。。。。。
Install 1 Package
Total download size: 4.4 M
Installed size: 17 M
Downloading packages:
gtk3-3.22.30-6.el7.x86_64.rpm | 4.4 MB 00:00:12
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : gtk3-3.22.30-6.el7.x86_64 1/1
Verifying : gtk3-3.22.30-6.el7.x86_64 1/1
Installed:
gtk3.x86_64 0:3.22.30-6.el7
Complete!
[root@localhost ~]# rpm -qa|grep chrome #原有的⾕歌被卸载了,其实⾕歌有⽤,并不想卸载呢,所有yum卸载连依赖⼀起卸载很危险,需要怎么解决这个问题
[root@localhost ~]#
[root@localhost ~]# ./firefox/firefox
[GFX1-]: glxtest: libEGL initialize failed
[GFX1-]: glxtest: X error, error_code=2, request_code=148, minor_code=3
[GFX1-]: glxtest: process failed (exited with status 1)
卸载之后报错,重装gtk3之后成功启动⽕狐浏览器
卸载了gtk2之后还是能启动⽕狐的,重新启动进程页⾯就正常加载出来
卸载gtk3,⾕歌浏览器被当做依赖误卸载掉
重装⾕歌
⾕歌还是能正常使⽤的
问题⼆复现及解决:
移除libXt⽂件,问题复现,重新yum安装,问题解决
[root@localhost ~]# ./firefox/firefox >/dev/null2>&1 &
[1] 9310
[root@localhost ~]# ps -ef|grep firefox
root 931092944809:13 pts/600:00:11 ./firefox/firefox
root 94379310909:13 pts/600:00:01 /root/firefox/firefox-bin -contentproc -childID 1 -isForBrowser -prefsLen 1 -prefMapSize 248973 -jsInit 285716 -parentBuildID 20210901125518 -appdir /root/firefox/browser 9310true root 94889310609:13 pts/600:00:00 /root/firefox/firefox-bin -contentproc -childID 2 -isForBrowser -prefsLen 160 -prefMapSize 248973 -jsInit 285716 -parentBuildID 20210901125518 -appdir /root/firefox/browser 9310 root 95249310609:13 pts/600:00:00 /root/firefox/firefox-bin -contentproc -childID 4 -isForBrowser -prefsLen 5583 -prefMapSize 248973 -jsInit 285716 -parentBuildID 20210901125518 -appdir /root/firefox/browser 9310 root 95419294009:13 pts/600:00:00 grep --color=auto firefox
[root@localhost ~]# rpm -qa|grep libXt
libXtst-1.2.3-1.el7.x86_64
libXt-1.1.5-3.el7.x86_64
yum remove libXt-1.1.5-3.el7.x86_64
Removed:
libXt.x86_64 0:1.1.5-3.el7
Dependency Removed:
dbus-x11.x86_64 1:1.10.24-15.el7 firefox.x86_64 0:78.14.s libXaw.x86_64 0:1.0.13-4.el7 libXmu.x86_64 0:1.1.2-2.el7
xorg-x11-server-utils.x86_64 0:7.7-20.el7 xorg-x11-xauth.x86_64 1:1.0.9-1.el7 xorg-x11-xinit.x86_64 0:1.3.4-2.el7 xterm.x86_64 0:295-3.el7_9.1
[root@localhost ~]# ./firefox/firefox
XPCOMGlueLoad error for file /root/firefox/libxul.so:
libXt.so.6: cannot open shared object file: No such file or directory
Couldn't load XPCOM.
[root@localhost ~]#
yum install -y libXt-1.1.5-3.el7.x86_64
Running transaction
Installing : libXt-1.1.5-3.el7.x86_64 1/1
Verifying : libXt-1.1.5-3.el7.x86_64 1/1
Installed:
libXt.x86_64 0:1.1.5-3.el7
[root@localhost ~]# ./firefox/firefox
Error: no DISPLAY environment variable specified
[root@localhost ~]# yum install -y xorg-x11-server-utils.x86_64 xorg-x11-xinit.x86_64
Installed:
xorg-x11-server-utils.x86_64 0:7.7-20.el7 xorg-x11-xinit.x86_64 0:1.3.4-2.el7
Dependency Installed:
libXmu.x86_64 0:1.1.2-2.el7 xorg-x11-xauth.x86_64 1:1.0.9-1.el7
[root@localhost ~]# ./firefox/firefox
Error: no DISPLAY environment variable specified
[root@localhost ~]# eval `dbus-launch --sh-syntax`
-bash: dbus-launch: command not found
[root@localhost ~]# yum install -y dbus-x11.x86_64
[root@localhost ~]# eval `dbus-launch --sh-syntax`
[root@localhost ~]# ./firefox/firefox
Error: no DISPLAY environment variable specified
重新打开⼀个会话窗⼝,成功启动进程
[root@localhost ~]# ./firefox/firefox >/dev/null2>&1 &
[1] 2333
[root@localhost ~]# ps -ef|grep firefox
root 233318912210:40 pts/200:00:04 ./firefox/firefox
root 24842333610:40 pts/200:00:01 /root/firefox/firefox-bin -contentproc -childID 1 -isForBrowser -prefsLen 1 -prefMapSize 249090 -jsInit 285716 -parentBuildID 20210901125518 -appdir /root/firefox/browser 2333true root 25362333010:40 pts/200:00:00 /root/firefox/firefox-bin -contentproc -childID 2 -isForBrowser -prefsLen 96 -prefMapSize 249090 -jsInit 285716 -parentBuildID 20210901125518 -appdir /root/firefox/browser 2333true root 26012333510:40 pts/200:00:00 /root/firefox/firefox-bin -contentproc -childID 4 -isForBrowser -prefsLen 5590 -prefMap
Size 249090 -jsInit 285716 -parentBuildID 20210901125518 -appdir /root/firefox/browser 2333 root 26652333210:40 pts/200:00:00 /root/firefox/firefox-bin -contentproc -parentBuildID 20210901125518 -prefsLen 5590 -prefMapSize 249090 -appdir /root/firefox/browser 2333true rdd
root 27181891010:40 pts/200:00:00 grep --color=auto firefox
需要安装的libXt依赖包总结:
libXt.x86_64 dbus-x11.x86_64 firefox.x86_64 libXaw.x86_64 libXmu.x86_64
xorg-x11-server-utils.x86_64 xorg-x11-xauth xorg-x11-xinit.x86_64 xterm.x86_64
[machangwei@aocxxx ~]$ rpm -qa|grep "libXt|dbus-x11|libXaw|libXmu|xorg-x11-server-utils|xorg-x11-xauth|xorg-x11-xinit|xterm"
[machangwei@aocxxx ~]$
firefox
问题3解决乱码:
Centos Firefox中⽂乱码(对Centos7/8都有效)
yum -y groupinstall Fonts
马上⽣效。
查看是否安装成功
下载依赖包到本地:
yum install --downloadonly --downloaddir=/root/mcw/prob1 libXt dbus-x11 libXaw libXmu dbus-x11 xorg-x11-server-utils xorg-x11-xauth xorg-x11-xinit xterm
yum groupinstall --downloadonly --downloaddir=/root/mcw/language Fonts
功能测试
windows上打开linux版浏览器测试,正常访问
windows上启⽤linux版⽕狐,需要安装图形化界⾯,安装xmanger,xshell启⽤xmanager
linux⽕狐能正常访问
python程序测试⽕狐浏览器是否能正常使⽤
#from selenium.webdriver.chrome.options import Options
from selenium.webdriver.firefox.options import Options
from time import sleep
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('/root/firefox/firefox')
# 创建⼀个参数对象,⽤来控制chrome以⽆界⾯模式打开
chrome_options = Options()
#chrome_options.add_argument('--headless') #⽆头浏览器
#chrome_options.add_argument('--disable-gpu')
#chrome_options.add_argument('--no-sandbox')
#chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--headless')
chrome_options.add_argument('blink-settings=imagesEnabled=false')
chrome_options.add_argument('--disable-gpu')
print("111111111111111111111")
#实例化⼀个浏览器对象
#bro = webdriver.Chrome(executable_path='/root/chromedriver',chrome_options=chrome_options)
#bro = webdriver.Firefox(executable_path='/root/geckodriver',firefox_options=chrome_options)
bro = webdriver.Firefox(executable_path='/root/geckodriver',firefox_options=chrome_options,firefox_binary=binary) #实例化⽕狐浏览器对象。指定浏览器启动⽂件
firefox_binary位置,指定浏览器驱动位置executable_path,指定启动参数,firefox_options
print("22222222222222222222222222222222")
<('www.baidu')
print("33333333333333333333333333")
sleep(2)
bro.save_screenshot('1.png')
print("4444444444444444444444444444444444444444")
print(bro.page_source)
sleep(1)
bro.quit()
执⾏程序,成功截图访问百度的页⾯
启动Linux版⽕狐浏览器,需要使⽤xmanger连接(4a登录的主机⽆法使⽤xmanager连接),⽀持图形化界⾯才能启动成功,并且在⾃⼰笔记本上打开图形化的linux⽕狐浏览器。之前进⼊了⼀个误区,安装了软件就需要启动。⾃动化测试只需要使⽤⽆头浏览器来调⽤⽕狐,启动⽕狐进程。所以⽆需安装图形化界⾯等,只需要解决⽕狐的缺少的库⽂件,
中⽂字符之类的问题,就可以使⽤程序测试是否能正常使⽤浏览器。
⽂档整理不全,可参考笔记信息:
#rpm -arch.rpm
启动命令,⽕狐启动后出来⽕狐浏览器中⽂乱码
./firefox/firefox >/dev/null 2>&1 &
/opt/google/chrome/google-chrome --disable-setuid-sandbox --user-data-dir --no-sandbox
/
opt/google/chrome/google-chrome --disable-setuid-sandbox --user-data-dir --no-sandbox >/dev/null 2>&1 &说明dbus没有建⽴,要安装必要的⼯具:
# apt-get install dbus-x11
运⾏ dbus-launch :
# dbus-launch
dbus命令没有
dbus-x11 yum安装
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论