Data extraction from website

nianchi111

Board Regular
Joined
Aug 24, 2007
Messages
184
Dear friends,

macro code:

Sub Gooney_Goo_Goo()
Dim ie As Object
Dim i As Long
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True 'Just for our test
.navigate "http://baselcatalog.messe.ch/mch/abo_sec_hall.asp?hall=1"
Do While .ReadyState <> 4: DoEvents: Loop
Do While .busy: DoEvents: Loop

With .document
For i = 0 To .links.Length - 1
If InStrB(1, .links(i).innerText, Auguste Reymond S.A.) Then
ie.navigate .links(i).href
Do While ie.ReadyState <> 4: DoEvents: Loop
Do While ie.busy: DoEvents: Loop
Exit For
End If
Next i
End With

End With
ActiveSheet.Cells(rrow, 2) = Split(ie.document.getElementById("contentdetail").innerText, vbCrLf)(0)
If ie.document.getElementById("contact").innerText <> "" Then
ActiveSheet.Cells(1, 3) = Split(ie.document.getElementById("contact").innerText, vbCrLf)(0)
ActiveSheet.Cells(1, 4) = Split(ie.document.getElementById("contact").innerText, vbCrLf)(1)
ActiveSheet.Cells(1, 5) = Split(ie.document.getElementById("contact").innerText, vbCrLf)(2)
ActiveSheet.Cells(1, 6) = Split(ie.document.getElementById("contact").innerText, vbCrLf)(3)
ActiveSheet.Cells(1, 7) = Split(ie.document.getElementById("contact").innerText, vbCrLf)(4)
ActiveSheet.Cells(1, 8) = Split(ie.document.getElementById("contact").innerText, vbCrLf)(5)
ActiveSheet.Cells(1, 9) = Split(ie.document.getElementById("contact").innerText, vbCrLf)(6)
End If
End If
ie.Quit
Loop
End Sub

I'm getting an error @ ActiveSheet.Cells(1, 9) = Split(ie.document.getElementById("contact").innerText, vbCrLf)(6).

Since there is no data in this field, how to pass this if there no data available.
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,999
Split once to get an array of lines, then loop through them, something like this (untested and uncompiled):
Code:
If ie.document.getElementById("contact").innerText <> "" Then
  Dim lines as variant, i as integer
  lines = Split(ie.document.getElementById("contact").innerText, vbCrLf)
  For i = Lbound(lines) to Ubound(lines)
    ActiveSheet.Cells(1, i+3) = lines(i)
  Next
End If
 

Forum statistics

Threads
1,141,218
Messages
5,705,076
Members
421,377
Latest member
FerdiFuchs

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top