# -*- coding:utf-8 -*-
from selenium import webdriver
import requests
from selenium.webdriver import ActionChains
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
# # 添加选课序号
# codes = []
# while True:
# code = raw_input(u'请输入选课序号(输入回车结束):')
# if code != '':
# codes.append(code)
# else:
# break
#
# # 开始登录
chrome_drive = '/usr/bin/chromedriver'
driver = webdriver.Chrome(executable_path=chrome_drive, chrome_options=options)
url = "https://cas.admore.com.cn/login?service=https%3A%2F%2Fadwords.admore.com.cn%2F"
s = requests.session()
def get():
print(1)
driver.get(url)
print(2)
name_input = driver.find_element_by_id('username') # 找到用户名的框框
pass_input = driver.find_element_by_id('userInputPassword') # 找到输入密码的框框
login_button = driver.find_element_by_xpath('//*[@id="checkFormInput"]/input[4]')
# action2 = driver.find_element_by_name("login")
name_input.clear()
name_input.send_keys('yanyan@ihesheng.com') # 填写用户名
pass_input.clear()
pass_input.send_keys('hihesheg123') # 填写密码
login_button.submit()
WebDriverWait(driver, 300000000).until_not(lambda x: x.find_element_by_class_name("hot-item ng-binding ng-scope").is_displayed()) # 等待直到登录成功
#is_displayed():判断元素是否显示
#is_selected():判断元素是否选中状态
# print(34556)
# ActionChains(driver).move_to_element(action2).click(action2).perform()
print(driver.page_source)
if '行业动态' in driver.page_source:
print("登录成功!")
selenium_cookies = driver.get_cookies() # 把selenium获取的cookies保存到变量,备用。
print(selenium_cookies)
for i in selenium_cookies:
print(i)
# driver.close()
else:
# driver.close()
print("结束")
get()
chromedriver下载地址:https://npm.taobao.org/mirrors/chromedriver/
参考:https://blog.csdn.net/helihongzhizhuo/article/details/82906279