VBA在网页自动化中有天然的优势,直接在EXCEL表格就能开始。可以直接将表格的内容填入网页中,对于很多需要上网页频发填写内容的行业非常适用。
VBA控制网页自动化最简单就是使用IE浏览器,但win10以上的版本IE都被淘汰了,合并到EDGE上。即使如很多网上攻略所说从EDGE上分离出来,也驱动不了。那怎么办?在偶然的机会上,发现360就是IE的天然替代者,360可以当IE来用,速度也还可以,(缺点大家都懂,有点流氓)。
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "https://XXXXX.com/"
' 等待网页加载完成
Do While ie.Busy Or ie.readyState <> 4
DoEvents
Loop
'点登录
Dim divs As Object
Set divs = ie.Document.getElementsByClassName("login-text")
For Each di In divs
di.Click
Next
' 等待网页加载完成
Do While ie.Busy Or ie.readyState <> 4
DoEvents
Loop
Application.Wait (Now + TimeValue("0:00:02"))
'输入账号、密码
ie.Document.getElementById("pcd_login_input_box_name").Value = "账号"
ie.Document.getElementById("pcd_login_input_box_key").Value = "XXXX"
Set divs2 = ie.Document.getElementsByClassName("login-btn-text")
For Each di2 In divs2
di2.Click
Next
Application.Wait (Now + TimeValue("0:00:02"))
' 等待网页加载完成