Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Get data from web site - hyperlinks in divs in html table
I need to download data from a web site. I'm familiar with how to use
an InternetExplorer object to navigate to the page etc. But how do I get this data: The web page source for the table of data I want looks like this: <table border="0" cellpadding="15" cellspacing="0" width="580" <tr <td class="copy" <div class="mahead"<bItem 1</b -- <a href="http:// www.website.com/webpage.html"view page</a</div <div class="mahead"<bOther Thing</b -- <a href="http:// www.website.com/someotherpage.html"view page</a</div <div class="mahead"<bNew Stuff</b -- <a href="http:// www.website.com/yetanotherpage.html"view page</a</div <br /<br /<br /<br /<br / </td </tr </table Where my example shows only three items, the real web page has many more, each as a <div, all in the same <td. What I need to get is: [Field 1] [Field 2] Item1 http://www.website.com/webpage.html Other Thing http://www.website.com/someotherpage.html New Stuff http://www.website.com/yetanotherpage.html How do I get that data? BTW, if I use Excel's Get External Data From Web feature, I get this table: [Field 1] [Field 2] Item1 view page Other Thing view page New Stuff view page With no sign of the urls, which I need. Thanks for any suggestions. Greg |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Get data from web site - hyperlinks in divs in html table
Greg
This will get all the links from that particular HTML code. Private Sub GetAllLinks() Dim IE As Object Dim doc As Object Dim lnks As Object Dim l Dim pos Dim rng As Range Set rng = Range("A1") Set IE = CreateObject("InternetExplorer.Application") IE.Visible = True IE.Navigate "C:\GetLinksFromDivsTest.html" Do While IE.Busy: DoEvents: Loop Do While IE.ReadyState < 4: DoEvents: Loop Set doc = IE.Document Set lnks = doc.getelementsbytagname("A") For Each l In lnks rng = l.innertext rng.Offset(, 1) = l Set rng = rng.Offset(1) Next l IE.Quit: Set IE = Nothing End Sub Similar code could be used to get all the tables, all the divs etc On Jun 22, 8:30*am, Greg Lovern wrote: I need to download data from a web site. I'm familiar with how to use an InternetExplorer object to navigate to the page etc. But how do I get this data: The web page source for the table of data I want looks like this: <table border="0" cellpadding="15" cellspacing="0" width="580" * * * * <tr * * * * * * * * <td class="copy" * * * * * * * * * * * * <div class="mahead"<bItem 1</b -- <a href="http://www.website.com/webpage.html"view page</a</div * * * * * * * * * * * * <div class="mahead"<bOther Thing</b -- <a href="http://www.website.com/someotherpage.html"view page</a</div * * * * * * * * * * * * <div class="mahead"<bNew Stuff</b -- <a href="http://www.website.com/yetanotherpage.html"view page</a</div * * * * * * * * * * * * <br /<br /<br /<br /<br / * * * * * * * * </td * * * * </tr </table Where my example shows only three items, the real web page has many more, each as a <div, all in the same <td. What I need to get is: [Field 1] * * * * * [Field 2] Item1 * * * * * * *http://www.website.com/webpage.html Other Thing * * *http://www.website.com/someotherpage.html New Stuff * * * *http://www.website.com/yetanotherpage.html How do I get that data? BTW, if I use Excel's Get External Data From Web feature, I get this table: [Field 1] * * * * * [Field 2] Item1 * * * * * * * view page Other Thing * * *view page New Stuff * * * * view page With no sign of the urls, which I need. Thanks for any suggestions. Greg |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Creating customized hyperlinks to a site | Excel Discussion (Misc queries) | |||
Copy a table from a web site, then manipulate the data? | Excel Worksheet Functions | |||
How can I cut data out of HTML table, into msExcel and just take the data & columns? (but NOT the formatting & URLs!) | Excel Discussion (Misc queries) | |||
Import External Data Non-HTML Table | Excel Discussion (Misc queries) | |||
Getting Table data from HTML page | Excel Programming |