在Linux中使用selenium(环境部署)

在Linux中使用selenium(环境部署)

1、安装chrome

用下面的命令安装Google Chrome

yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

也可以先下载至本地,然后安装

wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

yum install ./google-chrome-stable_current_x86_64.rpm

 

安装必要的库

yum install mesa-libOSMesa-devel gnu-free-sans-fonts wqy-zenhei-fonts

 

2、安装 chromedriver(末尾附chrome和chromedriver的对应版本)

chrome官网

wget https://chromedriver.storage.googleapis.com/2.38/chromedriver_linux64.zip

淘宝源(推荐)http://npm.taobao.org/mirrors/chromedriver/可也先进去看看

wget http://npm.taobao.org/mirrors/chromedriver/2.41/chromedriver_linux64.zip

 

将下载的文件解压,放在如下位置

unzip chromedriver_linux64.zip

mv chromedriver /usr/bin/

给予执行权限

chmod +x /usr/bin/chromedriver

 

3、运行代码,查看是否成功(python下)#当然你要先安装selenium

from selenium import webdriver

driver = webdriver.Chrome()

4、linux无头模式:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome(chrome_options=chrome_options)
#driver = webdriver.Chrome()
driver.get("https://www.baidu.com")

print(driver.page_source)
#driver.quit()

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值