ceacer 2 已发布 1月27号 分享 已发布 1月27号 自动获取信息免不了使用Selenium,毕竟直接用chrome访问兼容性最好,MAC下的Selenium好弄,但是在云服务器上花了一两天时间,碰到好多意外情况,值得记录一下。 一、基础环境信息 腾讯云服务器,因为申请的较早,使用了CentOS7.6,4核8G。 Python 3.6.8,Selenium 3.141.0。 Python的安装很简单,就不再赘述,Selenium直接用pip3安装即可。 二、具体步骤 1、Linux上安装Chrome浏览器 这是最坑的一个步骤,花的时间最长。 最初肯定是去下载稳定版本,于是使用wget下了一个126.0.6478.182版本。 wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm 结果使用yum或rpm安装chrome时提示,需要lib.so.6(GLIBC_2.25)(64bit)。 虽然提示可以用–skip-broken去跳过问题,但使用后无济于事,仍然报错,于是开始百度glibc库的升级,愕然发现也是一个大工程,简单来说就是2.25貌似不太稳定,建议直接到2.31,于是继续按步骤操作。 (1)下载glibc版本,检查升级前依赖 wget https://mirrors.aliyun.com/gnu/glibc/glibc-2.31.tar.gz tar -xzvf glibc-2.31.tar.gz cd glibc-2.31 cat INSTALL | grep -E "newer|later" | grep "*" # 输出如下 * GNU 'make' 4.0 or newer * GCC 6.2 or newer * GNU 'binutils' 2.25 or later * GNU 'texinfo' 4.7 or later * GNU 'bison' 2.7 or later * GNU 'sed' 3.02 or newer * Python 3.4 or later * GDB 7.8 or later with support for Python 2.7/3.4 or later * GNU 'gettext' 0.10.36 or later 检查了一下,发现在CentOS7.6版本中,make为3.82,gcc为4.x,gdb为7.6,需要升级。 (2)依赖包升级 首先是make wget https://mirrors.aliyun.com/gnu/make/make-4.3.tar.gz tar -xzvf make-4.3.tar.gz cd make-4.3 mkdir build cd build ../configure --prefix=/opt/make # 安装到/opt目录下 make && make install ln -sf /opt/make/bin/make /usr/bin/make # 最终验证make版本,应为4.3 make --version 然后是gcc wget https://ftp.gnu.org/gnu/gcc/gcc-9.3.0/gcc-9.3.0.tar.gz --no-check-certificate tar -xzvf gcc-9.3.0.tar.gz cd gcc-9.3.0 # 去gnu网站下载4个依赖包,这里花了不少时间,可能是网络带宽问题 ./contrib/download_prerequisites mkdir build cd build ../configure --enable-checking=release --enable-language=c,c++ --disable-multilib --prefix=/usr make -j4 # 使用4个核心,把服务器资源用足 make install # 最终验证gcc版本,应为9.3.0 gcc -v 最后是gdb。 wget http://ftp.gnu.org/gnu/gdb/gdb-7.8.tar.gz tar -xzvf gdb-7.8.tar.gz cd gdb-7.8 mkdir build cd build ../configure --prefix=/usr make make install # 此处会提示错误——configure: error: no termcap library found ## 先安装termcap wget https://ftp.gnu.org/gnu/termcap/termcap-1.3.1.tar.gz tar -xzvf termcap-1.3.1.tar.gz cd termcap-1.3.1 mkdir build cd build configure make make install # 然后回到gdb的build目录下重新执行编译 cd gdb-7.8/build make make install # 最终验证gdb版本,应为7.8 gdb -v (3)glibc升级 cd glibc-2.31 mkdir build cd build ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin --disable-sanity-checks --disable-werror make -j4 make install make localedata/install-locales # 解决新启动远程终端报警提示问题,这一步的时间最长 # 最终验证glibc版本 strings /lib64/libc.so.6 | grep -E "^GLIBC" | sort -V -r | uniq # 以下为验证命令输出 GLIBC_PRIVATE GLIBC_2.30 GLIBC_2.29 GLIBC_2.28 GLIBC_2.27 GLIBC_2.26 GLIBC_2.25 GLIBC_2.24 GLIBC_2.23 GLIBC_2.22 GLIBC_2.18 GLIBC_2.17 GLIBC_2.16 GLIBC_2.15 GLIBC_2.14 GLIBC_2.13 GLIBC_2.12 GLIBC_2.11 GLIBC_2.10 GLIBC_2.9 GLIBC_2.8 GLIBC_2.7 GLIBC_2.6 GLIBC_2.5 GLIBC_2.4 GLIBC_2.3.4 GLIBC_2.3.3 GLIBC_2.3.2 GLIBC_2.3 GLIBC_2.2.6 GLIBC_2.2.5 注意的是升级最终是以一个错误提示结束显示,一开始吓了一跳,以为没成功。 (4)安装Chrome 花费了大半天搞定glibc,结果安装chrome出现同样的提示,继续百度+大模型搜索,找到一篇文章说CentOS7无法安装126版本,貌似7.9和7.6版本都不行,只能使用124的版本。 wget http://dist.control.lth.se/public/CentOS-7/x86_64/google.x86_64/google-chrome-stable-124.0.6367.118-1.x86_64.rpm yum install google-chrome-stable-124.0.6367.118-1.x86_64.rpm # 最终验证chrome版本,应为124.0.6367.118 google-chrome --version 2、安装Chrome WebDriver 要安装与chrome版本对应的webdriver,可以去https://getwebdriver.com/chromedriver,页面上能看到的都是最新稳定版、Beta版、研发版或实验性版本(Canary),即126版本及更新的,要找之前的版本可以使用JSON API的结果,点击下图中的链接: 会列出所有版本的相关信息,找到124对应的版本号,发现有好多个。 可以选择与chrom的小版本号118相近的,如91、155、201等,试验了一下,发现这几个版本都可以使用,当然,大版本号不同是无法使用的,126的chromedriver启动就会提示版本信息不匹配。 wget https://storage.googleapis.com/chrome-for-testing-public/124.0.6367.201/linux64/chromedriver-linux64.zip unzip chromedriver-linux64.zip cd chromedriver-linux64 cp chromedriver /usr/local/bin # 最终验证chromedriver版本,应为124.0.6367.<小版本号> chromedriver --version 3、脚本验证 在脚本验证环节也出了一些小状况,因为在mac上用了比较熟,结果因为环境不同,相同的无头(headless)脚本在linux下就是不能用,后来发现,需要使用无沙箱模式启动才可以。 from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_argument('--headless') options.add_argument('--no-sandbox') browser = webdriver.Chrome(options = options) // 使用browser去浏览,使用等 browser.quit() 评论链接 在其他网站上分享 更多分享选项...
推荐帖
创建账户或登录以发表评论
您需要成为会员才能发表评论
创建一个帐户
在我们的社区注册一个新账户。很简单!
注册新账户登入
已有账户?在此登录
立即登录