Почему поиск Google VBA не ищет все ячейки в столбце? - PullRequest
0 голосов
/ 28 мая 2020

Привет, я пытаюсь заставить VBA запустить скрипт, чтобы вернуть все ссылки с первой страницы после запуска поиска в Google, но он не выполняет поиск во всех ячейках столбца последовательно.

Также может кто-нибудь помочь мне разделить гиперссылки и внутренний текст? Вот копия кода ниже:

'Start the bot called SearchBot
Sub SearchBot()

'declare/set aside memory for our variables
Dim wb As Workbook
Dim ws As Worksheet


Set wb = ActiveWorkbook
Set ws = ActiveSheet

For h = 1 To ws.Range("A1").CurrentRegion.Rows.Count
    Dim objIE As Object
    Dim aEIe As HTMLLinkElement
    Dim y As Integer
    Dim result As String

    'Start Internet Explorer
    Set objIE = New InternetExplorer

    'Make Internet Explorer Visible
    objIE.Visible = True

    'navigate to the google webpage
    objIE.navigate "google.com"

    'Wait for a few seconds while the browser is busy
    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop

    'in the search box enter the field from the cell and press search
    objIE.document.getElementsByName("q")(0).Value = ws.Cells(h, 1).Value

    SendKeys "{Enter}"

    'Wait again for the browser to finish

    Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop

    ws.Cells(h, 2).Select

    x = 0

    For Each aEIe In objIE.document.getElementsByClassName("r")


        ActiveCell = objIE.document.getElementsByClassName("r")(x).innerText
        ActiveCell.Offset(0, 1).Select
        x = x + 1
    Next

    objIE.Quit

Next



End Sub
...