Linux自动化测试框架selenium安装
程序员文章站
2022-05-08 11:06:08
...
1.安装Chrome
yum update
yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
2.查看Chrome版本
google-chrome-stable -version
3.注意接下来安装的Chromedriver一定要和Chrome版本对应上
Chromedriver下载地址:
Chromedriver
4.解压缩
yum install unzip
unzip chromedriver_linux64.zip
5. mv chromedriver /usr/bin/chromedriver
6.改变权限chmod +x /usr/bin/chromedriver
7.pip3 install selenium
8.测试
from selenium.webdriver.chrome.options import Options
from selenium import webdriver
import time
chrome_options = Options()
chrome_options.add_argument('--no-sandbox') # “–no - sandbox”参数是让Chrome在root权限下跑
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--headless') # “–headless”参数是不用打开图形界面(#浏览器不提供可视化页面. linux下如果系统不支持可视化不加这条会启动失败)
driver = webdriver.Chrome(chrome_options=chrome_options)
def spider():
driver.get("https://blog.csdn.net/xinlinliu/article/details/102940992")
while True:
driver.refresh()
driver.get("https://blog.csdn.net/xinlinliu/article/details/102940992")
time.sleep(10)
if __name__ == '__main__':
spider()