+ Reply to Thread
Results 1 to 2 of 2

Web Scraping data from a table with VBA?

  1. #1
    Forum Contributor
    Join Date
    12-29-2012
    Location
    usa
    MS-Off Ver
    Excel 2016
    Posts
    325

    Web Scraping data from a table with VBA?

    I am working on an Excel VBA project to scrape some specific information from a website. The view of this data on the website is as such:

    ukVGe.png

    What I am looking to do is extract text based on two criteria: Name and post date. For example, I have the name Kaelan and the post date of 11/16/2016. I want to extract the amount of $365.

    This is the HTML code:

    Please Login or Register  to view this content.
    This is the VBA code for my attempt.

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    So the above code will return the header descriptions of the table such as "Description, Post Date, Effective, Qty, Amount." How can I use this information where I am to extract information from a table below? Since I believe the actual amounts and dates are part of a table below the table where I have extracted information from.

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

    Re: Web Scraping data from a table with VBA?

    It is difficult to figure out where the tags are closed as what you have posted is not the full page.
    Since this looks like a table, you have a number of options- particularly as you are using IE.

    < div class="cmFloatLeft" id="divCategoryLabel_id_4541278" style="width: 430px;" >
    Kaelan
    < /div >
    1. You do not need to loop through as each line as the page has an ID attribute, which normally is unique per page.
    You get could use
    MyText=doc.GetElementByID("divCategoryLabel_id_4541278").innertext
    to extract Kaelan and do similar for the date and amount.

    2. You could also use class name to loop through each element in the collection.
    Set els = doc.getElementsByClassName("divListTableBodyLabel")
    if you know the index position of each element you want to extract you could some thing like

    Myamount= doc.getElementsByClassName("divListTableBodyLabel")(3).innertext ' the fourth element with in the collection.

    3. You could loop through the entire div which is the root of all the tables, trs,tds and other elements.
    4. Loop through table/s.
    5. If you know the exact position of the data, you could use like

    Myamount= doc.getElementsByTagName("tr")(1).innertext
    MyDate= doc.document.getElementsByTagName("td")(1).innertext
    Last edited by AB33; 09-23-2017 at 04:03 PM.

+ 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. Web Scraping Data Using VBA
    By zaska in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 02-25-2017, 09:52 PM
  2. [SOLVED] Data Scraping
    By underwater24 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-30-2016, 11:36 PM
  3. Identifying Table For Scraping By Excel VBA
    By gurs in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-22-2016, 04:21 AM
  4. VBA web data scraping from table
    By fotodj in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 08-25-2016, 03:18 PM
  5. Scraping/Importing Table
    By Madskillet in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-10-2016, 07:34 PM
  6. Scraping Data using VBA
    By Nala2355 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-16-2011, 11:21 AM
  7. Data scraping
    By brewers7 in forum Excel General
    Replies: 8
    Last Post: 02-06-2011, 12:45 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