+ Reply to Thread
Results 1 to 39 of 39

Scraping data from a website table

  1. #1
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Scraping data from a website table

    Hi, I am getting the following error message when I run the code below. The code works perfectly well when I used it on different websites.


    Run-time error '91':
    Object variable or With block variable not set




    I am not sure if its the code or the website that's causing the error?

    Please Login or Register  to view this content.

    Any suggestions? Thank you.
    Last edited by jjin; 08-09-2018 at 03:42 AM.

  2. #2
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Scraping data from a website table

    Longshot, try https:// instead of http://

  3. #3
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table

    Hi Kersplash, already using https://. Thanks.

  4. #4
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Scraping data from a website table

    Where does the code stop at?

  5. #5
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table

    It stops at this code: name = Trim(ele.getElementsByTagName("td")(2).innerText)

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Scraping data from a website table

    The page probably hasn't finished loading when this executes, so the elements probably don't exist yet:
    Please Login or Register  to view this content.
    This assumes that you have updated the code for the website you are working with, if you haven't, you'll need to update the above to match the page you're working with

  7. #7
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table

    Hi Kyle123, the code has already been updated for the website. or could that be something to do with a"show more" button on the webpage? When the webpage is fully loaded, it initially shows a list of around 20 items on the page and there is the "show more" button at the bottom of the page to display more items.

  8. #8
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Scraping data from a website table

    No idea without seeing it. My money would be on the page not having loaded when the code runs

  9. #9
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Scraping data from a website table

    Are you still using Excel 2010?

  10. #10
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table

    Hi Kersplash, I am using excel 2016. Thanks.

  11. #11
    Forum Expert kersplash's Avatar
    Join Date
    11-22-2016
    Location
    Perth
    MS-Off Ver
    Home 2016 (Windows 10)/Work 2013 Pro Plus (Windows 10)
    Posts
    2,012

    Re: Scraping data from a website table

    Maybe have a look at Power Query (Get & Transform) for website scraping.

  12. #12
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table

    Hi Kersplash, already tried the Power query but somehow excel couldn't connect to the webpage.

  13. #13
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table

    Hi Kyle123,

    Below is the HTML code that I see from the website.


    (div class="c-table-container")
    (table)
    (thead)(/thead)
    (tbody)
    (tr)
    (td class="c-table-custom")1780(/td)
    (td class="c-table-custom")1DDF(/td)
    (td class="c-table-custom")8788(/td)
    (/tr)
    (/tbody)
    (/table)
    (/div)
    When my code runs, it waits until the page is fully loaded.

    Any other suggestions?

  14. #14
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Scraping data from a website table

    Your code doesn't wait until the site is fully loaded. It waits until all the data is received - that's not the same thing. It is increasingly common for websites to build elements with JavaScript AFTER the page has loaded, your code does not wait for this.

    In the sample you have posted above, where did you get that from? The developer tools or View source? They are not the same thing, developer tools will show you the html as it is now ie after the javascript whereas view source will show you the actual html your code is using.

  15. #15
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table

    Hi Kyle123, oh I understand you now. I got the code from view source. In that case, is there any way I can modify my code above to wait until the page is fully loaded?

  16. #16
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Scraping data from a website table

    If you got it from View source, you don't need to.

    However, I've just spotted a mistake in your code:
    Please Login or Register  to view this content.
    Should be
    Please Login or Register  to view this content.

  17. #17
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table

    Hi Kyle123, You were correct. When I run the code again, the webpage gets opened but it doesn't wait till it is fully loaded. Is there any way I can make the code to wait until the page is fully loaded? Thank you.

  18. #18
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Scraping data from a website table

    If the information you need is in the source, then you don't need to. It's slowing your code down unnecessarily - though you aren't bothered about performance since you're using IE, so you just need to add a loop that keeps checking whether your element exists.

  19. #19
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table

    After hours of searching for the answer on the web, I realized that the webpage I am trying to pull the data from does not load any data when it is opened with IE (it loads the full list when opened with firefox). So after all, it had something to do with the web browser not the VBA.

    And I found out that other web browsers doesn't support VBA script. I am not sure what to do from here. Any suggestions?

  20. #20
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Scraping data from a website table

    What's the url?

  21. #21
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table


  22. #22
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Scraping data from a website table

    And which data are you wanting? There's a lot there under show more at the bottom

  23. #23
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table

    I am trying to get the full list of all the item names on the page (including the list under the show more). Thanks.

  24. #24
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Scraping data from a website table

    Like this, try it in a new blank workbook first:
    Please Login or Register  to view this content.

  25. #25
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table

    Hi Kyle123, sorry about the late reply. Your coding does what I wanted to achieve Thanks. You are a legend!!

  26. #26
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table

    Hi Kyle123, Once again, thank you so much for your help. I just have few more questions to ask you if that's ok.

    If I want to copy the rest of the data on the webpage, not just the company name (i.e. startup name, ico start, pre-start date, ..., goal), how can I modify your coding to do so? I just spent 4 hours to understand how your code works so I can tweak the code to achieve what I want to achieve (As I am still a newbie to VBA and JSON) but unfortunately I was out of luck but it was a good learning curve.

    One more data i am trying to get from the website is the URL address that's linked to the name of each company on the page (i was able to do this on other websites using my own VBA script but obviously mine didn't work on this website as the page was not properly being loaded on IE).

    Any suggestions or tips would be much appreciated.

  27. #27
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Scraping data from a website table

    Try such a modification

    Please Login or Register  to view this content.
    Last edited by YasserKhalil; 08-11-2018 at 05:36 AM. Reason: Added new fields
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  28. #28
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table

    Hi YasserKhalil, Awesome. It does the trick. Just urious where did you get those 'name, ticker, name_short, link' strings from? They are obviously not on the webpage and also in their HTML code? What I am trying to do is to copy all the data (start and end date, rating and so on) on the page to excel including the link url (which you have already made it happen). I am trying to understand how this works so i can apply it to other projects I am currently working on if that's ok. Thanks.

  29. #29
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Scraping data from a website table

    You're welcome.
    If you run the code line by line
    and stopped at this line
    Please Login or Register  to view this content.
    You will find the whole string

    another trick you can navigate to first page through this link
    https://icorating.com/ico/upcoming/l...l=true&search=
    and you will find the contents ...

  30. #30
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Scraping data from a website table

    Navigate to the url
    https://icorating.com/ico/upcoming/l...l=true&search=

    Now press Ctrl + A to select the whole content and Ctrl + C to copy

    Then go to this url
    http://jsonviewer.stack.hu/

    Then paste using Ctrl + V

    You will find a tab named "Viewer" where you can sew the JSON content

    Hope that this will help you

  31. #31
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208
    Awesome. you are a legend. much appreciated. there goes my weekend :P. Thanks

  32. #32
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Scraping data from a website table

    You're welcome. Glad we can offer some help
    And thanks a lot for Mr. Kyle for his awesome code. I have learned a lot from it

  33. #33
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table

    Hi YasserKhalil, Just two more questions. When I added few more strings to the code (i.e. "goal" and "presale_start_date"), I get the following error message:

    Run-time error 9":
    Subscript out of range

    And also how did you find your suggested URL link? https://icorating.com/ico/upcoming/l...l=true&search=

    Many thanks.

  34. #34
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Scraping data from a website table

    I have worked on the Kyle's code so I got the URL from his code ..
    As for the error can you post the code to have a look?

  35. #35
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table

    Sure.
    Please Login or Register  to view this content.
    I am getting error on the last two strings:
    Please Login or Register  to view this content.
    Thank you.

  36. #36
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Scraping data from a website table

    May be the cause of error is that the value is null (I am not sure)
    Try those two lines instead
    Please Login or Register  to view this content.

  37. #37
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table

    It returns the value of "20 instead of $20,000,000.

  38. #38
    Forum Contributor
    Join Date
    12-14-2012
    Location
    Perth
    MS-Off Ver
    Excel 2010
    Posts
    208

    Re: Scraping data from a website table

    I know this is a bit dirty way around but I can still work with it unless there is a cleaner way to do this.

    Please Login or Register  to view this content.
    I am still trying to figure out how to get the JSON Url (or text response view) as I have number of other websites I am trying to pull more data from. Any idea? Thanks.

  39. #39
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: Scraping data from a website table

    You really want to be parsing the JSON properly if you're wanting multiple things, try this module: https://github.com/VBA-tools/VBA-JSON

+ 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. VBA website scraping - multiple link clicks to show full table
    By Offspring21 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-17-2018, 11:24 AM
  2. [SOLVED] Help in scraping data from website
    By Chrispelletier in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-15-2018, 09:00 AM
  3. Trouble Scraping data from a website
    By chrisellis250 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-13-2017, 09:07 AM
  4. Cleaning up data from scraping website URL
    By king0r1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-27-2016, 08:42 AM
  5. [SOLVED] Scraping data from website
    By novicevba in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-22-2016, 11:02 AM
  6. Data Scraping from the WebSite
    By sathis in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-26-2015, 10:46 AM
  7. scraping data from a website
    By redpanda in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-05-2012, 01:20 PM

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