AutoHotkey
*官方文档
*官方网站

web自动化实现自动登录(QQ空间、防火墙)

from selenium import webdriver
import time
 
driver_path = r'D:\PrograApp\chromedriver\geckodriver.exe'
dr = webdriver.Firefox(executable_path=driver_path)
dr.get("https://qzone.qq.com/")
 
 
 
c = dr.find_element_by_css_selector('#login_frame')   #定位到该框架
dr.switch_to_frame(c)   #切换到该框架
dr.find_element_by_css_selector('#switcher_plogin').click()
time.sleep(2)
dr.find_element_by_css_selector('#u').send_keys('QQ账号')
time.sleep(2)
dr.find_element_by_css_selector('#p').send_keys('QQ密码')
time.sleep(2)
dr.find_element_by_css_selector('#login_button').click()

2、实现自动登录防火墙(FW)(自动输入账号、密码、验证码、登录) 

from selenium import webdriver
import time
import re
 
ew=''
dr = webdriver.Chrome()
dr.get('https://192.168.0.254:8889/')
dr.find_element_by_css_selector('li.fixline:nth-child(1) > input:nth-child(3)').clear()
dr.find_element_by_css_selector('li.fixline:nth-child(1) > input:nth-child(3)').send_keys('administrator')
dr.find_element_by_css_selector('li.fixline:nth-child(2) > input:nth-child(3)').send_keys('Bane@7766')
a = dr.find_element_by_id('checkinfo').find_elements_by_tag_name('img')
for i in a:
    w = i.get_attribute('src')
    qw = re.compile(r'/imgs/(.).gif')
    qw = qw.findall(w)
    for j in qw:
        ew+=j
dr.find_element_by_css_selector('#input1').send_keys(ew)
dr.find_element_by_css_selector('.login_btn2').click()
time.sleep(2)
f = dr.switch_to_alert()
print(f.text)
f.accept()

————————————————
[AHK]操控IE登录百度的示例

pwb := ComObjCreate("InternetExplorer.Application")
pwb.Visible := 1
pwb.Navigate("https://passport.baidu.com/v2/?login&tpl=mn")
while pwb.ReadyState <> 4
{}
pwb.document.getElementById("TANGRAM__PSP_3__userName").value := "用户名"
pwb.document.getElementById("TANGRAM__PSP_3__password").value := "密码"
pwb.document.getElementById("TANGRAM__PSP_3__submit").click()

比较优雅的写法

#h::
    pwb := ComObjCreate("InternetExplorer.Application")
    pwb.Visible := 1        
    weburl := "http://mail.163.com/index_alternate.htm"       ;keystring := "id:loginBtn"          
    ;~ weburl := "http://ahk8.com/forum-14.html"                       ;keystring := "tag:A&index:32"
    pwb.Navigate(weburl)                                                
    while pwb.ReadyState <> 4                                                                        
    {}    
        WinGetTitle, Title, A
        WinMaximize, %Title%
        
;~ ahk操作网页:点击网页按钮。

;~ 支持两种按钮定义方式 id 和tag
    keystring := "id:loginBtn"
    ;~ keystring := "tag:A&index:32"
    HtmlClickByKeyString(keystring, pwb)    
    HtmlClickByKeyString(keystring, pwb)                            
    {
        If (InStr(keystring,"id:"))
        {
            idstring :=LTrim(keystring,"id:")
            pwb.document.getElementById(idstring).click()
        }            
        If (InStr(keystring,"tag:"))
        {
            stringarray :=StrSplit(keystring, "&")
            tagstring :=LTrim(stringarray[1],"tag:")
            indexstring :=LTrim(stringarray[2],"index:")
            Inputs := pwb.document.getElementsByTagName(tagstring)                    
            Loop, % Inputs.length
            {
                if (A_index == indexstring)                                         
                    Inputs.item(A_index-1).Click()                                
            }   
        }    
    }

————————————————

最后修改:2021 年 05 月 12 日
如果觉得我的文章对你有用,请随意赞赏