Good Day,我正在开发一种工具,可以从各种网站上扣除“单向费用”。对于特定的网站,我处于可以导航到正确页面的阶段,但是我无法弄清楚如何将单向费用转换为excel。我还有一个问题,我似乎无法单击“后退”按钮。我的代码“有效”之处在于,如果您通过按F8键来遍历脚本,那么您将到达所需的位置。如果您正常运行,它有时会落在“ carclick.item(x).click零件”上。请注意,单向费用并不总是出现。当接送地点不同时,它最有可能出现。我的代码需要执行的任务如下:
然后,我需要单击“后退”按钮以返回到车辆选择并针对所有汽车组重复该操作。
Private Sub test1() Dim appIE As Object Dim ws As Worksheet Dim wb As Workbook Dim a As String Dim b As String Dim c As String Dim x As Integer Dim d As String Dim e As Object Dim l As Object Dim PickUp As Object Dim iL As IHTMLElement 'this declares the html object Dim f As IHTMLElementCollection ' this declares the collection of html objects Dim post As Object Dim Ret As Object Dim entry As Object Dim pd As Object Dim backbutton As Object Dim carclick As Object Set wb = Application.Workbooks("Hertz") Set ws = wb.Worksheets("One Way Fees") Set appIE = CreateObject("InternetExplorer.application") With appIE .Navigate "https://www.Hertz.co.za" .Visible = True Application.Wait (Now + TimeValue("0:00:03")) Do While appIE.Busy DoEvents Application.Wait (Now + TimeValue("0:00:03")) Loop Application.Wait (Now + TimeValue("0:00:03")) Set g = appIE.document.getElementById("return-location") g.Click Application.Wait (Now + TimeValue("0:00:03")) Do While appIE.Busy DoEvents Application.Wait (Now + TimeValue("0:00:03")) Loop Application.Wait (Now + TimeValue("0:00:03")) i = 2 'For i = 2 To 3 With ws a = 1267 d = 1261 b = "15 - May - 19" c = "25 - May - 19" End With For Each g In appIE.document.getElementsByClassName("return-location") If g.className = "return-location" Then g.Click Exit For End If Next g Do While appIE.Busy And e Is Nothing DoEvents Application.Wait (Now + TimeValue("0:00:02")) Loop Application.Wait (Now + TimeValue("0:00:02")) ' finds the pickup branch in html and clicks selection Set e = appIE.document.getElementById("pickup-depot") For Each O In e.Options If O.Value = a Then O.Selected = True Exit For End If Next Do While appIE.Busy And e Is Nothing DoEvents Application.Wait (Now + TimeValue("0:00:03")) Loop Application.Wait (Now + TimeValue("0:00:02")) 'sets the return branch and clicks the selection Set e = appIE.document.getElementById("return-depot") For Each O In e.Options If O.Value = d Then O.Selected = True Exit For End If Next Do While appIE.Busy And f Is Nothing DoEvents Application.Wait (Now + TimeValue("0:00:03")) Loop Do While appIE.Busy And l Is Nothing DoEvents Application.Wait (Now + TimeValue("0:00:01")) Loop Application.Wait (Now + TimeValue("0:00:01")) 'Clicking find a vehicle For Each l In appIE.document.getElementsByTagName("input") If l.className = "btn" Then l.Click Exit For End If Next Application.Wait (Now + TimeValue("0:00:04")) ' On Error Resume Next Do While appIE.Busy Application.Wait (Now + TimeValue("0:00:04")) DoEvents Loop 'While appIE.Busy Or appIE.readyState < 4: DoEvents: Wend Set carclick = appIE.document.querySelectorAll(".select-vehicle") For x = 1 To carclick.Length carclick.Item(x).Click 'While appIE.Busy Or appIE.readyState < 4: DoEvents: Wend Application.Wait (Now + TimeValue("0:00:02")) ' On Error Resume Next Do While appIE.Busy Application.Wait (Now + TimeValue("0:00:02")) DoEvents Loop 'This is where I tried to scrape the One-Way Fee value of 1315.79 'ws.Cells(2, 3).Value = appIE.document.querySelector(".sidebar__list- item:nth-of-type(13) span:nth-of-type(1)").innerText Application.Wait (Now + TimeValue("0:00:02")) ' On Error Resume Next Do While appIE.Busy Application.Wait (Now + TimeValue("0:00:02")) DoEvents Loop Set backbutton = appIE.document.querySelectorAll(".back.btn") backbutton.Click While appIE.Busy Or appIE.readyState < 4: DoEvents: Wend Exit For Next x End With End Sub