Extract data from website in an Excel Spreadsheet

sh_obaid

New Member
Joined
Dec 17, 2011
Messages
10
Hi all,

I am new to this forum and would like someone to please help me out. I have a website given below;

http://biz.yahoo.com/ic/524_cl_all.html

My Excel Spreadsheet has columns named "Hospital Name | Overview | Address | Phone | Fax | Contact Person 1 | Contact Person 1 Title | Contact Person 2 | Contact Person 2 Title | Contact Person 3 | Contact Person 3 Title"

There is the list of hospitals starting from "Abbott Northwestern Hospital". I have two things in my mind to extract the information. If you click on the first hospital name "Abbott Northwestern Hospital". Below is an example text which I would like to transfer it automatically in columns given above;

This text should go in column named "Overview":
Abbott Northwestern Hospital helps bring twins into the Twin Cities -- along with triplets, quadruplets............

This text should go in column named "Address": 800 E. 28th St.Minneapolis, MN 55407

This text should go in column named "Phone": 612-863-4000

This text should go in column named "Fax": 612-863-5667


This text should go in column named "Contact Person 1": Jeffrey D. (Jeff) Peterson

This text should go in column named "Contact Person 1 Title": President

This text should go in column named "Contact Person 2": Daryl Schroeder

This text should go in column named "Contact Person 2 Title": VP Operations

This text should go in column named "Contact Person 3": Sandy Schmitt

This text should go in column named "Contact Person 3 Title": VP Strategic Development, Allina Hospitals and Clinics

Please help, if there can be any script, macro or whatever could be helpful to automate the process.

Thanks and I look forward for any help.

Regards!
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hi,

I think kevin87's website is relevant for this. There are also many other resources that can help e.g.:

To get you started below is an example for retrieving the data from the first hospital. I'll leave it to you to clean this up to suit your needs and add the code necessary to loop through each Hospital (the resources above should help + many others - see Google).

Code:
' set references to Microsoft Internet Controls and Microsoft HTML Object Library
' (through Tools>References...)

Option Explicit

Sub example()

Dim page_url As String
Dim myIE As SHDocVw.InternetExplorer
    
Dim i As Long
    
'create new IE instance
Set myIE = New SHDocVw.InternetExplorer
'make IE window visible
myIE.Visible = True
'set page url
page_url = "http://biz.yahoo.com/ic/123/123489.html"
         
'load page
Call LoadWebPage(myIE, page_url)
ie_wait myIE

' overview
With myIE.document.getElementsByTagName("table")
    Cells(2, 2) = .Item(25).innerText ' overview
    
    ' Contact information
    i = 0
    Do Until .Item(i).Rows(0).innerText = "Contact Information"
        i = i + 1
    Loop
    Cells(2, 3) = .Item(i).Rows(1).Cells(1).innerText ' address
    Cells(2, 4) = .Item(i).Rows(2).Cells(1).innerText ' phone
    Cells(2, 5) = .Item(i).Rows(3).Cells(1).innerText ' fax
    
    ' Key people
    i = 0
    Do Until .Item(i).Rows(0).innerText = "Key People "
        i = i + 1
    Loop
    Cells(2, 6) = Mid(.Item(i).Rows(1).Cells(1).innerText, _
                    InStr(1, .Item(i).Rows(1).Cells(1).innerText, ":") + 2) ' Person 1
    Cells(2, 7) = Left(.Item(i).Rows(1).Cells(1).innerText, _
                    InStr(1, .Item(i).Rows(1).Cells(1).innerText, ":") - 1) ' Person 1 position
    Cells(2, 8) = Mid(.Item(i).Rows(2).Cells(1).innerText, _
                    InStr(1, .Item(i).Rows(2).Cells(1).innerText, ":") + 2) ' Person 2
    Cells(2, 9) = Left(.Item(i).Rows(2).Cells(1).innerText, _
                    InStr(1, .Item(i).Rows(2).Cells(1).innerText, ":") - 1) ' Person 2 position
    Cells(2, 10) = Mid(.Item(i).Rows(3).Cells(1).innerText, _
                    InStr(1, .Item(i).Rows(3).Cells(1).innerText, ":") + 2) ' Person 3
    Cells(2, 11) = Left(.Item(i).Rows(3).Cells(1).innerText, _
                    InStr(1, .Item(i).Rows(3).Cells(1).innerText, ":") - 1) ' Person 3 position
End With
        
'clean up
myIE.Quit 'close IE
Set myIE = Nothing
       
End Sub

'load web page
Function LoadWebPage(i_IE As SHDocVw.InternetExplorer, _
                     i_URL As String)
    With i_IE
        .Navigate i_URL 'open page
        Call ie_wait(i_IE) 'wait till it is loaded
    End With
End Function
        
'wait until IE finishes loading the page
Function ie_wait(i_IE As SHDocVw.InternetExplorer)
    Do While i_IE.Busy
        Application.Wait (Now + TimeValue("00:00:01"))
    Loop
End Function
 
Upvote 0
Should I use Visual Studio 2010 (I've installed it). Please tell me where to put this code?

Thanks!
 
Upvote 0
Okay, I got it. I did paste the entire code in Visual Basic Editor but it's giving me COMPILE ERROR and highlighting the code below:

Function LoadWebPage(i_IE As SHDocVw.InternetExplorer, _
i_URL As String

What can be the problem?

Also, I couldn't understand this:

' set references to Microsoft Internet Controls and Microsoft HTML Object Library
' through (Tools>References...)

I tried to go in tools in Internet Explorer but there is not any option named "References".
 
Upvote 0
You need to go to the Tools menu in the Visual Basic Editor not in Internet Explorer, and tick the references mentioned.
 
Upvote 0
I think I had to to go Tools>References using Visual Basic Editor but I found only Microsoft HTML Object Library.
 
Upvote 0
I found only Microsoft HTML Object Library and I have ticked that and tried again to run it but it's still giving me Compile Error and highlighting the code below;

Function LoadWebPage(i_IE As SHDocVw.InternetExplorer, _
i_URL As String
 
Upvote 0

Forum statistics

Threads
1,215,374
Messages
6,124,573
Members
449,173
Latest member
Kon123

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
Back
Top