zoukankan      html  css  js  c++  java
  • selenium获取cookie

     参考地址:https://www.cnblogs.com/lingwang3/p/7750156.html

    # 获取cookie
    import time
    from selenium import webdriver
    
    driver = webdriver.Chrome()
    driver.delete_all_cookies()
    login_url = 'https://sso.accounts.dowjones.com/login?client=5hssEAdMy0mJTICnJNvC9TXEw3Va7jfO&protocol=oauth2&redirect_uri=https%3A%2F%2Faccounts.wsj.com%2Fauth%2Fsso%2Flogin&scope=openid%20idp_id%20roles%20email%20given_name%20family_name%20djid%20djUsername%20djStatus%20trackid&response_type=code&nonce=02a76f8f-7b75-4095-82c4-ec8af2ae7e1a&connection=DJldap&ui_locales=en-us-x-wsj-19-2&mg=prod%2Faccounts-wsj&state=0k67vXdeRlXvGO2UEftM5cB0f-4Nt458#!/signin'
    driver.get(login_url)
    user = driver.find_element_by_css_selector('input[name="username"]')
    user.send_keys('zcw@live.com')
    pwd = driver.find_element_by_css_selector('input[name="password"]')
    time.sleep(2)
    pwd.send_keys('wise123')
    time.sleep(3)
    driver.find_element_by_css_selector('button[class="solid-button basic-login-submit"]').click()
    time.sleep(5)
    driver.switch_to_default_content()
    time.sleep(5)
    list_cookies = driver.get_cookies()
    for t in list_cookies:
        if t['name'] == 'djcs_session':
            djcs_session = t['value']
            break
        else:
            djcs_session = False
    
    if djcs_session:
        header = {
            "cookie": "djcs_session=%s" % djcs_session
        }
    else:
        exit("cookie get faild..")
    print(header)
  • 相关阅读:
    java设计模式----代理模式
    其他技术----nginx开光
    Less的使用
    C++ 引用和指针
    leetcode 220 Contains Duplicate
    python网络数据采集1
    404
    前端知识点
    tcl自动生成fifo empty checker
    漫话:如何给女朋友解释什么是"大案牍术"?
  • 原文地址:https://www.cnblogs.com/kongzhagen/p/8399508.html
Copyright © 2011-2022 走看看