from selenium import webdriver
import time
import requests
from yundama.dama import indetify
#实例化driver
driver = webdriver.Chrome()
driver.get("http://www.douban.com/")
#输入账号密码
driver.find_element_by_id("form_email").send_keys("784542623@qq.com")
driver.find_element_by_id("form_password").send_keys("zhoudawei123")

# 识别验证码3部
# 1. 获取验证码的url
captcha_img_url= driver.find_element_by_id("captcha_image").get_attribute("src")
# 2. 用requests.get()请求验证码的url，获得图片数据
captcha_content = requests.get(captcha_img_url).content
#3. 把验证码数据交给第三方云打码识别
captcha_code = indetify(captcha_content)
print("验证码的识别结果为:",captcha_code)


# 输入验证码
driver.find_element_by_id("captcha_field").send_keys(captcha_code)

time.sleep(5)
#点击登录
driver.find_element_by_class_name("bn-submit").click()

# 获取cookie
cookies = {i["name"]:i["value"]for i in driver.get_cookies()}
print(cookies)

time.sleep(3)
driver.quit()