首页 > temp > python入门教程 >
-
centos8 python+selenium环境搭建
安装CentOS 8桌面版
系统镜像名 CentOS-8.2.2004-x86_64-dvd1.iso
若无GUI,需安装
1
|
sudo dnf groupinstall "Server with GUI" |
安装vnc-server
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
sudo dnf install tigervnc - server - y vncpasswd # 设置密码 vncserver # 启动,报错了 dnf groupinstall 'gnome-desktop' cp / lib / systemd / system / vncserver@.service / etc / systemd / vncserver@: 1.service vim / etc / systemd / vncserver@\: 1.service # 将<USER> 改为要使用远程的用户名,如root vim / usr / lib / systemd / system / vncserver@.service # 将<USER> 改为要使用远程的用户名,如root systemctl daemon - reload systemctl start vncserver@: 1.service systemctl status vncserver@: 1.service systemctl enable vncserver@: 1.service |
参考:
https://zhuanlan.zhihu.com/p/126368045
https://www.cnblogs.com/zhengjinsheng/p/12888557.html
修改分辨率(注:用ssh登录到主机,再执行命令。在可视化界面的命令行中执行可能会报错)
vncserver -geometry 1920x1080 vncserver -list vncserver -kill :1
安装Chrome,安装完在root下启动需加参数
google-chrome-stable --no-sandbox
1
2
3
|
sudo dnf - y install wget wget https: / / dl.google.com / linux / direct / google - chrome - stable_current_x86_64.rpm sudo dnf localinstall google - chrome - stable_current_x86_64.rpm |
修改桌面启动,增加--no-sandbox
1
|
vi /usr/share/applications/google-chrome .desktop |
修改 Exec=/usr/bin/google-chrome-stable %U 在其后面加上 --no-sandbox
保存退出,点击桌面Chrome图标就能正常启动了
参考:https://www.freesion.com/article/4917281557/
安装中文输入法:
1
|
dnf install ibus-libpinyin.x86_64 -y |
之后可能需要重启
然后在设置中找到 【Region & Language】,在输入源中点+,选择汉语(中国),添加汉语(智能拼音)
然后在鼠标选中输入框时,在顶部右侧任务栏就可以切换为智能拼音,输入中文了。
1
|
pip3 install selenium |
下载对应浏览器的driver后,放到系统环境变量path目录下,如/usr/local/bin
https://chromedriver.chromium.org/
或 http://npm.taobao.org/mirrors/chromedriver/
https://github.com/mozilla/geckodriver/releases/
测试是否能打开浏览器了
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
from selenium import webdriver options = webdriver.ChromeOptions() options.add_argument( '--no-sandbox' ) options.add_argument( '--headless' ) options.add_argument( '--disable-gpu' ) options.add_argument( '--disable-dev-shm-usage' ) options.add_argument( 'user-agent=Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36' )<br data - filtered = "filtered" > browser = webdriver.Chrome(options = options) # browser = webdriver.Firefox() browser.get( 'https://www.ip138.com/useragent/' ) |
出处:https://www.cnblogs.com/ycc1/p/13792573.html