mardi 2 avril 2019

how do you input the details in to this site and extract the website data in to cell

need to input data in to website, 2 postcodes, then click the continue button and extract the distance in miles from the website and put it in to a cell.

i have tried a number of things getelementsbytagname and so on and taking inner details but struggling

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




Aucun commentaire:

Enregistrer un commentaire