+ Reply to Thread
Results 1 to 14 of 14

Need help selecting only the first ROW in a Table, Scraped from Web by MSXML2.HTML method!

  1. #1
    Registered User
    Join Date
    03-29-2017
    Location
    Europa
    MS-Off Ver
    2016
    Posts
    7

    Question Need help selecting only the first ROW in a Table, Scraped from Web by MSXML2.HTML method!

    How can i get the children "table" from the parent "table" (the table i'm after is in a bigger table, see below source code) and i want to get only the first row, but excluding a "form" from the Row (it's a href link)

    Untitled.jpg

    And how i can get this continuously (this table is dynamic, it's updating every time some one call me, this first Row, is updating continuously)



    The code below it's geting all the Parent Table and it's taking too long.
    Please Login or Register  to view this content.
    P.S. : i don't take any credits for this code, i manage to do it with help from different forums members!
    Last edited by mecanicu; 03-29-2017 at 07:07 AM.

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Need help selecting only the first ROW in a Table, Scraped from Web by MSXML2.HTML met

    objTable(0).Rows(0).Cells(0).innerText ' first table only.
    Try this one as well

    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    03-29-2017
    Location
    Europa
    MS-Off Ver
    2016
    Posts
    7

    Re: Need help selecting only the first ROW in a Table, Scraped from Web by MSXML2.HTML met

    AB33 Tx for fast replay!

    It's not working. I think because i did't describe my problem that good.
    "Set objTable = html.getElementsByTagName("table")" Now i'm calling "Parent table", but I need the "children table" it's class="TabelDate", it's a table in table (see source code from the 1st post, i have added notes and highlight for parent table, children table, row and every cells I need to get + the "href" i need to exclude, this "href" is located in the second cell of every row, it's contains information that i don't need)

    But i think even if we make it work, it's not the best approach. By feeding the code line by line (F8), when i past the information from "xml.responseText" to "html.body.innerHTML" I notice it's taking very long (it's taking the hole tabels that have 30500 Row's + every day adding 200 more, i only need 1 Row)
    Maybe i can use the XML DOM structure to get the single row i need and get it every second or every time it's changing (remember it's a call lag)
    By feeding it in excel i can build the table row by row

    Thank you
    Last edited by mecanicu; 03-29-2017 at 10:20 AM.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Need help selecting only the first ROW in a Table, Scraped from Web by MSXML2.HTML met

    It is because you are looping through the entire table. You got the whole table rows. You need to restrict the loop in to few rows. How many tables are on the page?
    What result did you get when you try objTable(0).Rows(0).Cells(0).innerText ?
    You can use a direct tag name with out loop, though you have to manually count the columns
    html.getElementsByTagName("td")(8).innerText

  5. #5
    Registered User
    Join Date
    03-29-2017
    Location
    Europa
    MS-Off Ver
    2016
    Posts
    7

    Re: Need help selecting only the first ROW in a Table, Scraped from Web by MSXML2.HTML met

    From what i can see the page contain only two, Parent Table and Children Table (the one i'm after)
    I'm getting an error when i try objTable(0).Rows(0).Cells(0).innerText. maybe i did't know how to use it:D

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Need help selecting only the first ROW in a Table, Scraped from Web by MSXML2.HTML met

    Since I can not read or see from a picture, we have to do a trial and error. Row 0 might not exist. From picture, there are 2 tables. The one you are looking is table 2, so the code should 1( Table starts from 0).
    You could include few of the rows to see which value is picked.

    Myvalue1=objTable(1).Rows(0).Cells(0).innerText

    Myvalue2=objTable(1).Rows(1).Cells(0).innerText

    Myvalue3=objTable(1).Rows(1).Cells(1).innerText

  7. #7
    Registered User
    Join Date
    03-29-2017
    Location
    Europa
    MS-Off Ver
    2016
    Posts
    7

    Re: Need help selecting only the first ROW in a Table, Scraped from Web by MSXML2.HTML met

    I manage to make it work. It's still slower that i wanted
    Set objTable = html.getElementsByTagName("table")
    ThisWorkbook.Sheets("LogClickPhone").Range("A2") = objTable(1).Rows(1).Cells(0).innerText
    ThisWorkbook.Sheets("LogClickPhone").Range("B2") = objTable(1).Rows(1).Cells(1).innerText
    ThisWorkbook.Sheets("LogClickPhone").Range("C2") = objTable(1).Rows(1).Cells(2).innerText
    ThisWorkbook.Sheets("LogClickPhone").Range("D2") = objTable(1).Rows(1).Cells(3).innerText
    ThisWorkbook.Sheets("LogClickPhone").Range("E2") = objTable(1).Rows(1).Cells(4).innerText

    Cells are injected in excel one by one not all at once. The second Cell still contains that href innerText that i don't want.
    Now how can i automate it to pull data automatically every time the Row from the web table is updating and add it to the top row in excel (on top of the older row's)

    Thank you very much AB33 for all you'r help, as you maybe notice, I'm a total noob at coding :D Tx

  8. #8
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Need help selecting only the first ROW in a Table, Scraped from Web by MSXML2.HTML met

    What do you mean by "Slower". The code is not looping. It is only copying 5 rows. How is that slow? Are you still using a loop?
    The second Cell still contains that href innerText that i don't want.
    What is the value you are getting?

  9. #9
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Need help selecting only the first ROW in a Table, Scraped from Web by MSXML2.HTML met

    try using
    application.screenupdating = false
    at the start of your code

    and don't forget to turn it back on at the end
    application.screenupdating = true


    this will help speed up your code and will also show the results replaced in one go rather than individually which is what your code does anyway.
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  10. #10
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Need help selecting only the first ROW in a Table, Scraped from Web by MSXML2.HTML met

    this is never going to be lightening quick as you are first of all going to a web page, then loading your username and password, then waiting for the page to reload

    how long is it taking? 3- 5 seconds?

  11. #11
    Registered User
    Join Date
    03-29-2017
    Location
    Europa
    MS-Off Ver
    2016
    Posts
    7

    Re: Need help selecting only the first ROW in a Table, Scraped from Web by MSXML2.HTML met

    It's not looping but i'm using "Set objTable = html.getElementsByTagName("table")" this is loading the hole object in "objTable". That object contains the hole content of the page(30500 Row's +).
    After that i'm searching for the row i need.
    So to keep it simple. How can i get the exact element's, or to be quicker the exact row i need not the hole "Parent table"

    Regarding the text i don't want, pleas see below source code (the innerText i'm getting in in black font)
    Untitled2.jpg
    Sorry that i'm using pictures to post Source Code but i don't know how to copy text from ""Inspect element"

  12. #12
    Registered User
    Join Date
    03-29-2017
    Location
    Europa
    MS-Off Ver
    2016
    Posts
    7

    Re: Need help selecting only the first ROW in a Table, Scraped from Web by MSXML2.HTML met

    Quote Originally Posted by Sean Thomas View Post
    this is never going to be lightening quick as you are first of all going to a web page, then loading your username and password, then waiting for the page to reload

    how long is it taking? 3- 5 seconds?
    With application.screenupdating = on off, it's taking 38.5 Seconds
    Without application.screenupdating = on off, it's taking 38.7 Seconds
    I'm 100% application.screenupdating is not doing anything.
    As for sending user and pass then waiting for page to load, by using F8 i can determin it's taking 13.4 Seconds
    So the biggest delays come from parsing the xml.responsText to html.body.innerHTML and load the hole object and then search for the row....

  13. #13
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Need help selecting only the first ROW in a Table, Scraped from Web by MSXML2.HTML met

    Set objTable = html.getElementsByTagName("table")
    You are not loading anything but assigning the table object to another object.
    This can not affect the speed.

  14. #14
    Registered User
    Join Date
    03-29-2017
    Location
    Europa
    MS-Off Ver
    2016
    Posts
    7

    Re: Need help selecting only the first ROW in a Table, Scraped from Web by MSXML2.HTML met

    So i'm stuck with this, i guess for now it will do.
    Now a more excel vba problem, but related with this.
    How to automate this so it's firing every 60 Seconds or so and populate the New Row in the second Row in excel A2,B2,C2,D2,E2. The Older Rows need to "step down" in excel table (A3,B3, etc) to make place for New Rows

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Assigning value for each scraped row based on another cell
    By Anka in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-14-2016, 08:03 PM
  2. Replies: 2
    Last Post: 01-07-2016, 12:25 PM
  3. How to Organize Scraped Data
    By anartey in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 12-20-2015, 02:13 AM
  4. web extract via swarm method - getting html objects and/or tables possible?
    By JasperD in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-12-2015, 05:35 PM
  5. Cleaning up Data Scraped From the Web by Deleting Certain Rows
    By torchD. in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-20-2015, 10:52 AM
  6. VBA to Import HTML Table Locally Stored HTML file to excel
    By ermengard in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-09-2015, 10:48 AM
  7. hii all is there any method to openthe html using vb command
    By vipul027 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2014, 05:32 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1