excel - Fetched table data from a webpage not displaying first column of table -
I need to bring the price table from this page:
So far I have developed this code Data received
sub-tableExample () dim the object object as a dim document object strunk string as strURL = "http://www.kieskeurig.nl/objectief/ Canon / ef_100mm_f2_usm / prijzen / bezorgen / 167,557 # prijzen "'replace your choice with IE = CreateObject's URL (" InternetExplorer.Application ") with IE' .Visible = True .navigate strURL unless .readyState = 4: DoEvents: Loops .Busy: DoEvents: Loops T-Doc = IE.document GetAllTables Dock. Quit End End Sub Sub GetAllTables (in the form of doc object) 'get a webpage document, get all the tables from the document, and the worksheet dims as a RNG Range Put the new worksheet into the dim tbl object as RW cl slow slow object long dim nextrow long dim as I set the length of the ws = sheet ("Sheet1") as doc.getElementsByTagName in each tbl (" Table ") for tabno = tabno + 1 In the form of tabno dim as Nextrow = advance + 1 set rng = ws.Ran GE ("B" & amp; Nextrow) rng.Offset (, -1) = "Table" & amp; Set each rw rw.Cells rng.Value = cl.innerText in tbl.Rows for each CL in tabno = rng.Offset (, 1) I = I + 1 next cl nextrow = nextrow + 1 set RNG = rng.Offset (1, i) i = 0 next rw next tbl ws.Cells.ClearFormats end sub This code works for me
But the problem is 1 ie i Supplier data column is not visible in the table brought.
Anyone can help me on this
with the following Change your GetAllTables subroutine: sub GetAllTables (as a doc object) 'get a webpage document, get all the tables from the document, and put them in a new worksheet Dim ws worksheet dim RNG range as dull as the tbl object in the form of retarded object as CL object C slow nextrow long dim as long as set ws = sheet ("Sheet1") for each as tabno dim Tbl these doc.getElementsByTagName ("tab") tabno = tabno + 1 nextrow = nextrow + 1 set rng = ws.Range ("B" and "Next") rng.Offset (, -1) = "Table" and am P; For each RW, tbl.Rows colno = 1 for each RW rw.Cells for each cl if colno = 1 and nextrow> 1 set set classColl = doc.getElementsByClassName ("shopLogoX") imgTgt = classColl (nextrow - 2) .getElementsByTagName ("img") rng.Value = imgTgt (0) .getAttribute ("alt") or else rng.Value = CL .inner text end if set rng = rng.Offset (, 1) I = I + 1 colno = colno + 1 next cl nextrow = nextrow + 1 set rng = rng.Offset (1, -I) I = 0 next rw The next tbl Ws.Cells.ClearFormats End is very low, in fact we can call colno to find out which columns are already in line. Code> is obviously, we check that we are in the first cell If we are on the first column and are not on the first line (the header row), then we create a collection of elements with the class shopLogoX . It has img tags in which alt is the attribute we want. Tried, tested and working. Let us know that it helps.
Comments
Post a Comment