+ Reply to Thread
Results 1 to 16 of 16

Help scraping data from webpage into a sheet based on date

Hybrid View

ozbad5243 Help scraping data from... 11-23-2016, 02:50 PM
AB33 Re: Help scraping data from... 11-23-2016, 03:01 PM
AB33 Re: Help scraping data from... 11-23-2016, 03:57 PM
ozbad5243 Re: Help scraping data from... 11-23-2016, 04:09 PM
AB33 Re: Help scraping data from... 11-23-2016, 04:16 PM
ozbad5243 Re: Help scraping data from... 11-23-2016, 04:22 PM
AB33 Re: Help scraping data from... 11-23-2016, 04:24 PM
ozbad5243 Re: Help scraping data from... 11-23-2016, 04:25 PM
AB33 Re: Help scraping data from... 11-23-2016, 04:58 PM
ozbad5243 Re: Help scraping data from... 11-23-2016, 05:15 PM
AB33 Re: Help scraping data from... 11-23-2016, 05:40 PM
ozbad5243 Re: Help scraping data from... 11-23-2016, 06:12 PM
AB33 Re: Help scraping data from... 11-23-2016, 06:16 PM
ozbad5243 Re: Help scraping data from... 11-23-2016, 06:26 PM
AB33 Re: Help scraping data from... 11-23-2016, 06:40 PM
ozbad5243 Re: Help scraping data from... 11-23-2016, 06:43 PM
  1. #1
    Registered User
    Join Date
    11-15-2016
    Location
    nowhere, somewhere
    MS-Off Ver
    MS office 365
    Posts
    8

    Help scraping data from webpage into a sheet based on date

    Hello everyone,

    I am stuck at how to format this data so it will fill only if the dates match.

    My code pulls in this text from the monitoring website as a string called UpStream and Downstream
    "Current pool (EL): 301.42 (m) at 11/23/2016 21:20"
    "Current tailwater (EL): 252.27 (m) at 11/23/2016 21:15

    Here is the code for the string (not sure how to format on here)



    [CODE]
    Set allRowOfData = ie.document.getElementByid("pool")
    Dim UpStream As String: UpStream = allRowOfData.innertext

    Set allRowOfData = ie.document.getElementByid("tail")
    Dim DownStream As String: DownStream = allRowOfData.innertext
    [CODE]



    My master sheet is set up by month and then each day is on the sheet in Row 8. I would like to have my VBA check if the date in Cell A8 is the same as in the string, if it is a match to place the Upstream in A6 and Downstream in A7 and if not, then to ignore it
    Attached Files Attached Files
    Last edited by ozbad5243; 11-23-2016 at 06:44 PM.

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

    Re: Help scraping data from webpage into a sheet based on date

    Could you attach the code with a sample excel book?

    Click on GO ADVANCED, scroll down and click Manage Attachments.

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

    Re: Help scraping data from webpage into a sheet based on date

    Ah,
    I did not know you have attached a sample. Okay, I understand the site requires log-in details, but I have worked out from the text you posted. Now, the issue is: are you comfortable to adjust the code.?On the attached, I have added two codes.
    The bottom one is TestCode. I used it to test the code using the text you posted. I have another code called UpDowdStream. This code is linked to your code; that is, it is called from your main code. So, my test code runs on its own, but the UpDowdStream can only be called from another code. If you see the data in X6 is filled with a date. What I have not done, or not sure is how both dates differ. Both are the same date, so do you want to fill in both A6 and A7 with the same date?
    Attached Files Attached Files
    Last edited by AB33; 11-23-2016 at 04:00 PM.

  4. #4
    Registered User
    Join Date
    11-15-2016
    Location
    nowhere, somewhere
    MS-Off Ver
    MS office 365
    Posts
    8

    Re: Help scraping data from webpage into a sheet based on date

    The data on the website updates daily so I want to be able to open the file, run the VBA and have it pull in the latest elevation (301.42 or whatever the new level is) into the upstream (A6) and the downstream into A7 based on if the dates match from what the server gives me "Current pool (EL): 301.42 (m) at 11/23/2016 21:20"

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

    Re: Help scraping data from webpage into a sheet based on date

    You have a single date in row 8, so there can only be a single date to match. Row 8 does not a time. Have you tried the code, if so what is the issue you are having?

    The problem we are having is, I can not access the site to test it. I am only working on assumption.

  6. #6
    Registered User
    Join Date
    11-15-2016
    Location
    nowhere, somewhere
    MS-Off Ver
    MS office 365
    Posts
    8

    Re: Help scraping data from webpage into a sheet based on date

    Correct, I wish I could give you access but if you go to that website its some sensitive data. If I could parse out the time stamp that would be great, I just want the code to "look" if the date in Row 8 matches the date in bold, if it matches I want it to put the elevation of the upstream and downstream in their respective cells.

    I am looking through your code right now and I think I can edit it to suit my purposes, I will let you know!

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

    Re: Help scraping data from webpage into a sheet based on date

    Ah!
    If the date match, you want to return the up and down elevation number in A6 and A7? Am I right?

  8. #8
    Registered User
    Join Date
    11-15-2016
    Location
    nowhere, somewhere
    MS-Off Ver
    MS office 365
    Posts
    8

    Re: Help scraping data from webpage into a sheet based on date

    yes! Exactly what I'm looking for!

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

    Re: Help scraping data from webpage into a sheet based on date

    Try the attached. Run and test it. You might got an error as I have not tested it on real data, but it works on my sample test. If the split does not work, I need to find another way of extracting the dates and numbers.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    11-15-2016
    Location
    nowhere, somewhere
    MS-Off Ver
    MS office 365
    Posts
    8

    Re: Help scraping data from webpage into a sheet based on date

    getting a "Run-time Error '13': Type Mismatch

    On Upstream in UpDowdstream

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

    Re: Help scraping data from webpage into a sheet based on date

    I can not see this word "UpDowdstream" on my code.
    I have cheated the site and pretended I have got the upstream and downstream values and the code seems to work.
    Could you please run it step by step using F8 and see in which line errors. I have also included msgbox to see if the site is returning the correct data.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    11-15-2016
    Location
    nowhere, somewhere
    MS-Off Ver
    MS office 365
    Posts
    8

    Re: Help scraping data from webpage into a sheet based on date

    so there is a period I missed at the end of the "Current tailwater (EL): 252.27 (m) at 11/23/2016 21:15." and that seems to be throwing off the code. Once I add the . to the test code it produces the mismatch error.

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

    Re: Help scraping data from webpage into a sheet based on date

    Does the code return

    "Current pool (EL): 301.42 (m) at 11/23/2016 21:20"
    "Current tailwater (EL): 252.27 (m) at 11/23/2016 21:15
    ?
    I asked you to run the code using F8 and to see if these values appear on message box, but it does not appear you are following my guide. Please let's take step by step.

  14. #14
    Registered User
    Join Date
    11-15-2016
    Location
    nowhere, somewhere
    MS-Off Ver
    MS office 365
    Posts
    8

    Re: Help scraping data from webpage into a sheet based on date

    The code returns "Current pool (EL): 301.41 (m) at 11/24/2016 01:10." and "Current tailwater (EL): 252.28 (m) at 11/24/2016 01:15." Note the added period at the end now. Would that cause it to throw a mismatch?

    Appreciate the help, you have no idea how big the impact of this working will be.

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

    Re: Help scraping data from webpage into a sheet based on date

    Yes, if there is a dot, it is not longer a date, but a string. This is quick fix, while I work on replacing it with different approach.
    Try it and see if this quick fix it.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    11-15-2016
    Location
    nowhere, somewhere
    MS-Off Ver
    MS office 365
    Posts
    8

    Re: Help scraping data from webpage into a sheet based on date

    Thank you AB33! Works like a charm!

+ 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. Scraping Java Webpage into Excel 2013
    By free008 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-11-2023, 10:04 AM
  2. Replies: 4
    Last Post: 10-16-2015, 12:59 PM
  3. Formula to pull data from one sheet to a new sheet based on date range
    By lisajolley11 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-15-2015, 08:38 PM
  4. [SOLVED] Webpage scraping into Excel - Run-time error '438': Object doesn't support this property..
    By kaseyleigh in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 12-29-2014, 08:15 AM
  5. [SOLVED] VBA Code to Pull Data from a Sheet Based on Date and Add that Data to Another Sheet
    By drsadistic in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-09-2014, 12:53 AM
  6. scraping a webpage for flood info
    By yarrick22 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-13-2014, 02:35 AM
  7. [SOLVED] Macro to copy date to specific sheet based on data from another sheet.
    By RichTea88 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 08-09-2013, 11:28 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