Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Scrape data from currently opened webpage into Excel

Status
Not open for further replies.

dvirgint

Programmer
Jun 28, 2010
85
CA
Hello,

I have been trying to read up on scraping data from an opened IE page but I have not been able to find anything. All documents I've seen open a blank page and then navigate to a given address.

What I need is quite simply (or it seems to me to be), is to get the "breadcrumbs" list into a Excel cell.

The elements of the breadcrumb list are as follows:
HTML:
<!-- Breadcrumb begins -->
<div id="cn-bcrumb">
<ol>
   <li><a href="Page">[highlight #FCE94F]Home[/highlight]</a></li>
   <li><a href="Page2">[highlight #FCE94F]Menu1[/highlight]</a></li>
   <li><a href="Page3">[highlight #FCE94F]Menu2[/highlight]</a></li>
</ol>
</div>
<!-- Breadcrumb ends / Fin du fil d'Ariane -->

What I need to have in the cells in Excel are the highlighted elements.

Can someone please help?
 
If you already have an open IE window at the right page, you need to find it. One way is ...

First, you will need references to the "Microsoft HTML Object Library" and "Microsoft Internet Controls".

Then code along these lines should get you where you need to be ..

Code:
[blue]
    Dim IEWindows           As SHDocVw.ShellWindows
    Dim IEwindow            As SHDocVw.InternetExplorer
    Dim IEDocument          As MSHTML.HTMLDocument
    Dim BreadcrumbDiv       As MSHTML.HTMLElementCollection
    
    Set IEWindows = New SHDocVw.ShellWindows
 
    For Each IEwindow In IEWindows
        If InStr(IEwindow.LocationURL, "your URL or some unique string") <> 0 Then  [green]' Found it[/green]
           Set IEDocument = IEwindow.Document
           Set BreadcrumbDiv = IEDocument.getElementById("cn-bcrumb")
           
           [green]' Now you should have the DIV with all the bits, so ...
           ' .. use the code you would have used if you had navigated there yourself[/green]

        End If
    Next
[/blue]

Clearly you'll need some error checking and other housekeeping, but that should get you going.



Enjoy,
Tony

------------------------------------------------------------------------------------
We want to help you; help us to do it by reading this: Before you ask a question.

I'm working (slowly) on my own website
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top