您如何将详细信息输入到此站点并将网站数据提取到单元格中

时间:2019-04-03 00:19:53

标签: web extract

我需要将数据输入网站,输入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

0 个答案:

没有答案