|
-
May 10th, 2006, 07:43 AM
#1
Thread Starter
Member
[RESOLVED] Extracting HTML Table Data using DOM
I am try to create a program that would extract song title, album name from AOL Music Page. Here is the link.
http://music.aol.com/artist/coldplay/435023/video
Data is given in a table. I have been trying to do it with "For Each table In wb.Document.body.getElementsByTagName("table")" code. But the problem is it gives some error. Dont worry about the error, the basic problem is I am not at all familiar with extracting data from tables. I know how to do it from normal pages using .innerhtml, .innertext etc but not from tables.
Can someone provide me a sample code to extract data from the above mentioned page?
Last edited by Inman; May 10th, 2006 at 09:40 AM.
-
May 10th, 2006, 09:40 AM
#2
Thread Starter
Member
Re: Extracting HTML Table Data using DOM
Never mind, I figured it out. If anyone needs to know, just reply.
-
May 10th, 2006, 09:49 AM
#3
Frenzied Member
Re: Extracting HTML Table Data using DOM
 Originally Posted by Inman
Never mind, I figured it out. If anyone needs to know, just reply.
Inman i am intrested in knowing how that can be done.
-
May 10th, 2006, 11:15 AM
#4
Thread Starter
Member
Re: [RESOLVED] Extracting HTML Table Data using DOM
It is very simple. You can call it just like an Excel control.
VB Code:
Dim testarray(10)
Dim ObjElement As HTMLObjectElement
Set ObjElement = Form1.WebBrowser1.Document.All().tags("table").Item(0)
For i = 0 To ObjElement.rows.length - 1
testarray(i) = ObjElement.rows(i).cells(0).innerText
Next i
What happens is the contents of first table in the page are copied to the array.
-
May 10th, 2006, 11:22 AM
#5
Frenzied Member
Re: [RESOLVED] Extracting HTML Table Data using DOM
many thanks for u reply. could u tell me what refrences and what controles do i need to run this code and where the output will be shown.Thanks
-
May 10th, 2006, 11:34 AM
#6
Thread Starter
Member
Re: [RESOLVED] Extracting HTML Table Data using DOM
You need to add a referece to Microsoft HTML Object Library.
In the above code, the data is stored into testarray. Since only the row variable is being looped, only the 1st column of the table will be stored into the array. i.e.
testarray(0) = ObjElement.rows(0).cells(0).innerText [ i.e. (row 1, column 1)]
testarray(1) = ObjElement.rows(1).cells(0).innerText [ i.e. (row 2, column 1)]
If you want 2nd column's value,
testarray(0) = ObjElement.rows(0).cells(1).innerText [ i.e. (row 1, column 2)]
Like that it works.
-
May 10th, 2006, 11:49 AM
#7
Frenzied Member
Re: [RESOLVED] Extracting HTML Table Data using DOM
 Originally Posted by Inman
You need to add a referece to Microsoft HTML Object Library.
In the above code, the data is stored into testarray. Since only the row variable is being looped, only the 1st column of the table will be stored into the array. i.e.
testarray(0) = ObjElement.rows(0).cells(0).innerText [ i.e. (row 1, column 1)]
testarray(1) = ObjElement.rows(1).cells(0).innerText [ i.e. (row 2, column 1)]
If you want 2nd column's value,
testarray(0) = ObjElement.rows(0).cells(1).innerText [ i.e. (row 1, column 2)]
Like that it works.
Thank u for u reply. So u mean i need a webbrowser controle with a button . How i can display the result in a listview ? It would be helpf full if u upload a sample project since i want to learn to do the same for another music website by extracting artistname,albumname,songname ,... So from your code i see u do most of the things without parsing wich makes life easier!
-
May 10th, 2006, 12:57 PM
#8
Thread Starter
Member
Re: [RESOLVED] Extracting HTML Table Data using DOM
Okay. Consider you have a webpage which has a table. You have a listview with corresponding number of columns as of webpage table called lv. To copy all contents of the table to lv.
VB Code:
Dim ObjElement As HTMLObjectElement
Set ObjElement = Form1.WebBrowser1.Document.All().tags("table").Item(0)
lv.listitems.clear
itmc=0
For i = 0 To ObjElement.rows.length - 1
itmc=itmc+1
lv.listitems.add itmc , , ObjElement.rows(i).cells(0).innerText
For j = 1 To ObjElement.cols.length - 1
lv.listitems(itmc).listsubitems.add , , ObjElement.rows(i).cells(j).innerText
next j
Next i
-
May 11th, 2006, 07:21 AM
#9
Frenzied Member
Re: [RESOLVED] Extracting HTML Table Data using DOM
Inmant thank u for u nice explanation. Could u look at this post of mine . I have some difficulty getting data from html.Thanks
http://www.vbforums.com/showthread.php?t=404705
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|