zoukankan      html  css  js  c++  java
  • python selenium 自动登录博客园

    1、直接上代码

    # coding:utf-8
    import time
    import os
    from selenium import webdriver
    from selenium.webdriver.common.action_chains import ActionChains
    
    path = os.path.abspath("./actuateModel")+"/IEDriverServer.exe"
    
    option = webdriver.IeOptions()
    option.add_argument('headless')
    
    driver = webdriver.Ie(executable_path=path)
    # url = "http://192.168.14.249/portal/"
    url = "https://account.cnblogs.com/signin?returnUrl=http%3a%2f%2fi.cnblogs.com%2f"
    
    driver.get(url=url)
    
    button = driver.find_element_by_xpath("//button[@id='submitBtn']")
    driver.find_element_by_xpath("//input[@name='LoginName']").send_keys("you name")
    driver.find_element_by_xpath("//input[@name='Password']").send_keys("you passwd")
    
    # text = driver.find_element_by_xpath("//input[@name='LoginName']").get_attribute("value")
    # print(text)
    button.submit()
    
    cookie1 = driver.get_cookies()
    
    time.sleep(6)
    
    href = driver.find_element_by_xpath("//div[@id='blog_title']/a").get_attribute("href")
    # driver.add_cookie(cookie1[0])
    driver.get(url=href)
    
    # 实例化鼠标对象 鼠标移入标签事件
    action = ActionChains(driver)
    # 鼠标移动到该元素上,鼠标悬停,等待下拉框元素可见
    ele = driver.find_element_by_xpath("//div[@class='dropdown'][3]")
    action.move_to_element(ele).perform()
    time.sleep(4)
    
    href1 = driver.find_element_by_xpath("//div[@class='dropdown'][3]/div[@class='dropdown-content']/a[@class='menu'][1]").get_attribute("href")
    
    driver.get(href1)
    
    time.sleep(3)
    
    href2 = driver.find_element_by_xpath("//div[@id='ipython']/iframe").get_attribute("src")
    
    driver.get(href2)
    
    href3 = driver.find_element_by_xpath("//tbody/tr[4]/td/a").get_attribute("href")
    
    driver.get(href3)
    

      

  • 相关阅读:
    axios 配置
    vue 配置App.js
    vue 挂载方式
    常用的js
    vuex
    vue搭建环境
    JS中 toString() & valueOf()
    html-webpack-plugin 中使用 title选项设置模版中的值无效
    webpack为什么加载不了css?
    visual studio for mac 安装文件
  • 原文地址:https://www.cnblogs.com/wuzaipei/p/11013504.html
Copyright © 2011-2022 走看看