小白学爬虫-在无GUI的CentOS上使用Selenium+Chrome
爬虫代理IP由芝麻HTTP服务供应商提供
各位小伙伴儿的采集日常是不是被JavaScript的各种点击事件折腾的欲仙欲死啊?好不容易找到个Selenium+Chrome可以解决问题!
但是另一个▄█▀█●的事实摆在面前,服务器都特么没有GUI啊··
好吧!咱们要知难而上!决不能被这个点小困难打倒·······
然而摆在面前的事实是···· 他丫的各种装不上啊!坑爹啊!
那么我来拯救你们于水火之间了!
服务器如下:
[root@spider01 ~]# hostnamectl
Static hostname: spider01
Icon name: computer-vm
Chassis: vm
Machine ID: 1c4029c4e7fd42498e25bb75101f85b6
Boot ID: f5a67454b94b454fae3d75ef1ccab69f
Virtualization: kvm
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-514.6.2.el7.x86_64
Architecture: x86-64
安装Chromeium:
## 安装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/目录下:
完成结果如下:
[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:
[root@spider01 ~]# yum install Xvfb -y [root@spider01 ~]# yum install xorg-x11-fonts* -y
新建在/usr/bin/ 一个名叫 xvfb-chromium 的文件写入以下内容:
[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
更改软连接
## 更改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
来瞅瞅能不能用哦:
>>> 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
No problem!!!!
好了部署完了!当然Docker这么火贼适合懒人了!来来 看这儿 Docker版的 妥妥滴!
docker pull thsheep/chromium-xvfb-py3:master
做好了Python3.6.3和Chrome集成
需要自己使用Dockerfile来重新打包安装你需要的Python包。
顺便一提!!!!这个玩意儿从事Web测试工作的小伙伴可以用!!!!!!!!
小白学爬虫-在无GUI的CentOS上使用Selenium+Chrome的更多相关文章
- 芝麻HTTP:在无GUI的CentOS上使用Selenium+Chrome
各位小伙伴儿的采集日常是不是被JavaScript的各种点击事件折腾的欲仙欲死啊?好不容易找到个Selenium+Chrome可以解决问题! 但是另一个▄█▀█●的事实摆在面前,服务器都特么没有GUI ...
- 第十四章 web前端开发小白学爬虫
老猿从事IT开发快三十年了,接触互联网也很久了,但自己没有做过web前端开发,只知道与前端开发相关的一些基本概念,如B/S架构.html标签.js脚本.css样式.xml解析.cookies.http ...
- 第14章 web前端开发小白学爬虫结束语
老猿学爬虫应该是2019年7月初开始的,到现在2个多月了,有段时间了,这部分一直是老猿期待能给大家带来收获的,因为老猿爬虫实战应用的场景与网上老猿已知的场景基本都不一样,是从复用网站登录会话信息来开发 ...
- 小白学爬虫-设置Selenium+Chrome代理
微博登录限制了错误次数···加上Cookie大批账号被封需要从Cookie池中 剔除被封的账号··· 需要使用代理··· 无赖百度了大半天都是特么的啥玩意儿???结果换成了 Google手到擒来 分分 ...
- 【小白学爬虫连载(10)】–如何用Python实现模拟登陆网站
Python如何实现模拟登陆爬取Python实现模拟登陆的方式简单来说有三种:一.采用post请求提交表单的方式实现.二.利用浏览器登陆网站记录登陆成功后的cookies,采用get的请求方式,传入c ...
- 小白学爬虫-批量部署Splash负载集群
整体目录如下: study@study:~/文档/ansible-examples$ tree Splash_Load_balancing_cluster Splash_Load_balancing_ ...
- puppeteer部署到centOS上出现launch chrome fail的情况
在Mac上调试无问题,放到阿里云上运行会报错. 需要先安装依赖, yum install pango.x86_64 libXcomposite.x86_64 libXcursor.x86_64 lib ...
- 小白学 Python 爬虫(3):前置准备(二)Linux基础入门
人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 Linux 基础 CentOS 官网: https: ...
- 小白学 Python 爬虫(4):前置准备(三)Docker基础入门
人生苦短,我用 Python 前文传送门: 小白学 Python 爬虫(1):开篇 小白学 Python 爬虫(2):前置准备(一)基本类库的安装 小白学 Python 爬虫(3):前置准备(二)Li ...
随机推荐
- 【转】 C/C++程序员必须熟练应用的开源项目
作为一个经验丰富的C/C++程序员, 肯定亲手写过各种功能的代码, 比如封装过数据库访问的类, 封装过网络通信的类,封装过日志操作的类, 封装过文件访问的类, 封装过UI界面库等, 也在实际的项目中应 ...
- 【转】我读过最好的epoll讲解(来自知乎)
首先我们来定义流的概念,一个流可以是文件,socket,pipe等等可以进行I/O操作的内核对象.不管是文件,还是套接字,还是管道,我们都可以把他们看作流.之后我们来讨论I/O的操作,通过read,我 ...
- 读书共享 Primer Plus C-part 4
第四章 字符串和格式化输入输出 关于printf - 左对齐 #include<stdio.h> void main() { char str [100] = "liuchua ...
- Hive metastore源码阅读(三)
上次写了hive metastore的partition的生命周期,但是简略概括了下alter_partition的操作,这里补一下alter_partition,因为随着项目的深入,发现它涉及的地方 ...
- 页面刷新方式实时检测cookie是否失效
在浏览器端每隔10秒钟刷新一次页面,可用于检查cookie值是否失效. 在study.php文件中存在这样一条语句: <meta http-equiv="refresh" c ...
- golang urlencode
u := url.Values{} u.Set(") u.Set(") u.Set(,"mac":"38:a4:ed:fe:99:c8"}` ...
- 洛谷P4014 分配问题【最小/大费用流】题解+AC代码
洛谷P4014 分配问题[最小/大费用流]题解+AC代码 题目描述 有 n 件工作要分配给 n 个人做.第 i 个人做第 j 件工作产生的效益为c ij. 试设计一个将 n 件工作分配给 n 个人做的 ...
- CENTOS6.6下mysql5.6的源码安装
本文来自我的github pages博客http://galengao.github.io/ 即www.gaohuirong.cn 1.下载:当前mysql版本到了5.6.28 http://dev. ...
- 基于Centos7的autobahn-python+crossbar的环境搭建
一.基于centos7的crossbar安装(已经安装好python) (1) sudo yum update (2) sudo yum install gcc gcc-c++ make openss ...
- Spring context:property-placeholder 一些坑
今天在配置多配置文件的时候偶然发现如果我使用 <context:property-placeholder location="classpath:filePath.properti ...