zoukankan      html  css  js  c++  java
  • python+selenium个人学习笔记9-文件上传和cookie操作

    文件上传

    一、文件上传

    1、input标签文件上传

    driver.find_element_by_name(“xxx”).send_keys("C:chen.py")

    2、非input标签文件上传

    暂无

    二、cookie操作

    1、get_cookies(): 获得所有cookie信息

    driver.get_cookies()

    2、add_cookie(cookie_dict) : 添加cookie

    driver.add_cookie({"name": "value"})

    3、get_cookie(name):获取制定name的cookie

    driver.get_cookie(name="value")

    4、delete_cookie():清除指定cookie

    driver.delete_cookie(name="value")

    示例:

    复制代码
    from selenium import webdriver
    from time import sleep
    driver = webdriver.Chrome()
    driver.implicitly_wait(10)
    #打开登录页面前获取cookies
    print(driver.get_cookies())
    driver.get("https://passport.cnblogs.com/user/signin")
    # 打开登录页面后获取cookies
    print(driver.get_cookies())
    # 登录后获取cookies
    driver.implicitly_wait(30)
    driver.find_element_by_id("input1").send_keys(u"chen")
    driver.find_element_by_id("input2").send_keys(u"xxx")
    driver.find_element_by_id("signin").click()
    sleep(10)#手动配合验证
    print(driver.get_cookies())
    # 获取指定name的cookie
    print(driver.get_cookie(name=".CNBlogsCookie"))
    # 清除指定name的cookie
    driver.delete_cookie(name=".CNBlogsCookie")
    print(driver.get_cookies())
    # 清除所有的cookie
    driver.delete_all_cookies()
    print(driver.get_cookies())
    driver.quit()
    复制代码
  • 相关阅读:
    Good Subarrays(思维)
    Just h-index(主席树裸题)
    强联通入门
    Fragrant numbers(dfs爆搜+区间dp+stoi)
    Mr. Panda and Kakin (RSA 解密+解同余方程+O(1)快速乘)
    Balance of the Force (枚举+线段树+二分图)
    2019 ICPC上海站K.Color Graph
    Wi Know (思维+线段树)
    Linux zookeeper 安装
    javaBIO
  • 原文地址:https://www.cnblogs.com/txx403341512/p/9353793.html
Copyright © 2011-2022 走看看