centos服务器端运行python+selenium+webdriver出现报错

利用python+selenium+webdriver在阿里云centos服务器运行爬虫,进行模拟登录教务系统+获取cookie的操作。代码如下:

from selenium import webdriver
from selenium.webdriver.support.select import Select
import time

options = webdriver.ChromeOptions()
options.add_argument('blink-settings=imagesEnabled=false')
driver = webdriver.Chrome(chrome_options=options,
                          executable_path="C:\\Users\\86155\\AppData\\Local\\Google\\Chrome\\Application\\chromedriver.exe")
driver.maximize_window()

'''登陆教务系统'''
url = 'http://uaaap-swu-edu-cn-s.sangfor.vpn.swu.edu.cn:8118/cas/login?service=http%3A%2F%2Fjw.swu.edu.cn%2Fsso%2Fzllogin'
driver.get(url)
driver.find_element_by_xpath('//*[@id="username"]').send_keys('测试账号')
driver.find_element_by_xpath('//*[@id="password"]').send_keys('测试密码')
'''登陆前页面验证'''
print(driver.find_element_by_xpath('//*[@id="loginForm"]/div/div/h3').text)
driver.find_element_by_xpath('//*[@id="loginForm"]/div/div/div/div[5]/a[1]').click()
time.sleep(1)

'''登陆后浏览器刷新原页面'''
'''登陆后页面验证(从这里开始报错)'''
print(driver.find_element_by_xpath('//*[@id="yhxxIndex"]/div/div/p').text)
cookies = driver.get_cookies()

在电脑上运行良好成功获得了cookie,然而在服务器端超时运行、然后报错,图片如下:

img

第一次单纯的只取cookie,取得cookies后,存储到文件。
下次使用cookies的时候,先打开要使用cookies的页面,然后加载cookies,最后再要使用cookies的页面刷新一次,就可以了。