как вы вводите данные на этот сайт и извлекаете данные сайта в ячейку - PullRequest
0 голосов
/ 03 апреля 2019

Мне нужно ввести данные на веб-сайт, 2 почтовых индекса, затем нажать кнопку продолжения, извлечь расстояние в милях от веб-сайта и поместить его в ячейку.

Я пробовал несколько вещей, таких как getelementsbytagname и так далее, и брал внутренние детали, но изо всех сил

Private Sub CommandButton1_Click()

'Sub postcode distance calc()

'dimension (declare or set aside memory for) our variables
Dim objIE As InternetExplorer 'special object variable representing the IE browser
Dim ele As Object
Dim y As Integer

'''''''''''''''''''''''''''''''''''''''''''
'OPEN INTERNET

'initiating a new instance of Internet Explorer and asigning it to objIE
    Set objIE = New InternetExplorer

'make IE browser visible (False would allow IE to run in the background)
    objIE.Visible = True

'''''''''''''''''''''''''''''''''''''''''''
'OPEN PAGE

'navigate IE to this web page (a pretty neat search engine really)
    objIE.Navigate "http://www.postcode-distance.com/distance-between-postcodes"

'make IE browser visible (False would allow IE to run in the background)
    objIE.Visible = True

'wait here a few seconds while the browser is busy
    Do While objIE.Busy = True Or objIE.ReadyState <> 4: DoEvents: Loop

'wait seconds
    Application.Wait Now + TimeValue("00:00:05")

'''''''''''''''''''''''''''''''''''''''''''

'enter details in to page

    'in the search box put cell
    objIE.Document.getElementById("zipcode1").Value = _
    Sheets("FRAUD ISSUES; INDIVIDUALS").Range("O4").Value

    'wait here a few seconds while the browser is busy
    Do While objIE.Busy = True Or objIE.ReadyState <> 4: DoEvents: Loop

    'wait seconds
    Application.Wait Now + TimeValue("00:00:01")


'enter details in to page

    'in the search box put cell
    objIE.Document.getElementById("zipcode2").Value = _
    Sheets("FRAUD ISSUES; INDIVIDUALS").Range("O5").Value

    'wait here a few seconds while the browser is busy
    Do While objIE.Busy = True Or objIE.ReadyState <> 4: DoEvents: Loop

    'wait seconds
    Application.Wait Now + TimeValue("00:00:01")

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'click the button
    objIE.Document.getElementByClass("formgowide").Click

'wait here a few seconds while the browser is busy
    Do While objIE.Busy = True Or objIE.ReadyState <> 4: DoEvents: Loop

'wait seconds
    Application.Wait Now + TimeValue("00:00:05")

'''''''''''''''''''''''''''''''''''''''''''''''''''''
'TAKE SITE MILES

'find distance
    Distance = objIE.Document.getElementsByid("outputDiv")(0).getElementsByTagName("br")(0).innerText
    Distance = Split(Distance, vbNewLine)(1)

'add distance to sheet
    Range("L6").Value = Distance

'''''''''''''''''''''''''''''''''''''''''''''''''''''

    'wait here a few seconds while the browser is busy
    Do While objIE.Busy = True Or objIE.ReadyState <> 4: DoEvents: Loop

'''''''''''''''''''''''''''''''''''''''''''''''''''''

'close the browser
    objIE.Quit

'''''''''''''''''''''''''''''''''''''''''''
'exit our SearchBot subroutine and start new row for new website data
    End Sub
...