centos 安装Selenium+Chrome
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了centos 安装Selenium+Chrome,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2385字,纯文字阅读大概需要4分钟。
内容图文
![centos 安装Selenium+Chrome](/upload/InfoBanner/zyjiaocheng/981/b8fd872e5d8c49539d1f92a825214d01.jpg)
参照https://cuiqingcai.com/4886.html
1 2 3 4 | ## 安装yum源 [root@spider01 ~]# sudo yum install -y epel-release ## 安装Chrome [root@spider01 ~]# yum install -y chromium |
去这个地方:https://sites.google.com/a/chromium.org/chromedriver/downloads 下载ChromeDriver驱动放在/usr/bin/目录下:
完成结果如下:
Shell ?1 2 3 | [root@spider01 ~]# ll /usr/bin/ | grep chrom -rwxrwxrwx. 1 root root 7500280 11月 29 17:32 chromedriver lrwxrwxrwx. 1 root root 47 11月 30 09:35 chromium-browser -> /usr/lib64/chromium-browser/chromium-browser.sh |
安装XVFB:
1 2 | [root@spider01 ~]# yum install Xvfb -y [root@spider01 ~]# yum install xorg-x11-fonts* -y |
新建在/usr/bin/ 一个名叫 xvfb-chromium 的文件写入以下内容:
Shell ?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | [root@spider01 ~]# cat /usr/bin/xvfb-chromium #!/bin/bash _kill_procs() { kill -TERM $chromium wait $chromium kill -TERM $xvfb } # Setup a trap to catch SIGTERM and relay it to child processes trap _kill_procs SIGTERM XVFB_WHD=${XVFB_WHD:-1280x720x16} # Start Xvfb Xvfb :99 -ac -screen 0 $XVFB_WHD -nolisten tcp & xvfb=$! export DISPLAY=:99 chromium --no-sandbox --disable-gpu$@ & chromium=$! wait $chromium wait $xvfb |
更改软连接:
Shell ?1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | ## 更改Chrome启动的软连接 [root@spider01 ~]# ln -s /usr/lib64/chromium-browser/chromium-browser.sh /usr/bin/chromium [root@spider01 ~]# rm -rf /usr/bin/chromium-browser [root@spider01 ~]# ln -s /usr/bin/xvfb-chromium /usr/bin/chromium-browser [root@spider01 ~]# ln -s /usr/bin/xvfb-chromium /usr/bin/google-chrome [root@spider01 ~]# ll /usr/bin/ | grep chrom* -rwxrwxrwx. 1 root root 7500280 11月 29 17:32 chromedriver lrwxrwxrwx. 1 root root 47 11月 30 09:47 chromium -> /usr/lib64/chromium-browser/chromium-browser.sh lrwxrwxrwx. 1 root root 22 11月 30 09:48 chromium-browser -> /usr/bin/xvfb-chromium -rwxr-xr-x. 1 root root 73848 12月 7 2016 chronyc lrwxrwxrwx. 1 root root 22 11月 30 09:48 google-chrome -> /usr/bin/xvfb-chromium -rwxrwxrwx. 1 root root 387 11月 29 18:16 xvfb-chromium |
1 2 3 4 5 6 | >>> from selenium import webdriver >>> driver = webdriver.Chrome() >>> driver.get("http://www.baidu.com") >>> driver.find_element_by_xpath("./*//input[@id='kw']").send_keys("哎哟卧槽") >>> driver.find_element_by_xpath("./*//input[@id='su']").click() >>> driver.page_source |
内容总结
以上是互联网集市为您收集整理的centos 安装Selenium+Chrome全部内容,希望文章能够帮你解决centos 安装Selenium+Chrome所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。