我有以下代码,获取一些数字并搜索它们并返回与该数字相关的名称
Private bot As New Selenium.ChromeDriver
Const sURL As String = "http://portal.acs.moi.gov.kw/wps/portal/!ut/p/c1/04_SB8K8xLLM9MSSzPy8xBz9CP0os3jHEEf3EENTIwMLD1dLA88Qv2AzMzM3IwMDU6B8JJK8v3-AmYGRr7G3qYmvhwEQENAdDrIPv36QvAEO4Gig7-eRn5uqH6kfZY7THncz_cic1PTE5Er9gtwIgyyTUEUANhX2ig!!/dl2/d1/L0lJSklna21DU1EhIS9JRGpBQU15QUJFUkNKRXFnL1lGTkExTkk1MC01Rjg5dyEvN19BVEFHVDE1MjA4SEU5MElUTlM2NjZGMjBHNi86bF9fXzQ1LzE5MTU4MzUzNTk!/?"
Sub Test()
Dim eleSearch As Selenium.WebElement, m As Long, lr As Long, r As Long, cnt As Long
lr = shSheet1.Cells(Rows.Count, 1).End(xlUp).Row
m = shSheet1.Cells(Rows.Count, 2).End(xlUp).Row + 1
With bot
'.AddArgument "--headless"
.Get sURL
.SwitchToAlert.Accept
For r = m To lr
'If r Mod 10 = 0 Then ThisWorkbook.Save
Application.StatusBar = "Civil ID: " & shSheet1.Cells(r, 1).Value & " ------- Row " & r
STARTPOINT:
With .FindElementByName("numberValue")
.Clear: .SendKeys shSheet1.Cells(r, 1).Value
End With
.FindElementByName("search").Click
shSheet1.Cells(r, 2).Value = Trim(.FindElementByXPath("/html/body/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td/div/table/tbody/tr/td/form/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/tr[1]/td/table/tbody/tr/td[1]/table/tbody/tr[3]/td/table/tbody/tr/td[2]").Text)
Dim eleNewSearch As Selenium.WebElement
Set eleNewSearch = Nothing
On Error Resume Next
Set eleNewSearch = .FindElementById("openNewSearch")
On Error GoTo 0
If Not eleNewSearch Is Nothing Then
.FindElementById("openNewSearch").Click
.Wait 2000
cnt = 0
Else
.FindElementByName("showViolations").Click
.Wait 2000
.SwitchToAlert.Accept
If cnt = 5 Then
cnt = 0
GoTo NXT
Else
GoTo STARTPOINT
End If
cnt = cnt + 1
End If
.Wait 1000
.SwitchToAlert.Accept
NXT:
Next r
End With
Application.StatusBar = Empty
MsgBox "Done...", 64, "YasserKhalil"
End Sub
当使用F8键时,一切都很好,工作得很好,但是当运行代码来执行任务时,它部分工作,并显示我错误页面。什么好主意吗?284083101217
、283042604438
、292082601615
的若干检验数字
我觉得你输入数字后点击太快了。试着在进入&点击:
With .FindElementByName("numberValue")
.Clear: .SendKeys shSheet1.Cells(r, 1).Value
End With
.Wait 2000
.FindElementByName("search").Click
可能是网站上的某种DDoS防御?