The Easiest Way to Scrape Web Data with VBA

Sdílet
Vložit
  • čas přidán 28. 03. 2022
  • Learn how to write real-world Excel VBA code: 👉courses.excelmacromastery.com/
    Want to download the source code for this video? Go here: bit.ly/3NrfGt4
    Subscribe to the channel here: bit.ly/36hpTCY
    The Easiest Way to Scrape Web Data with VBA
    In this video I show you how to scrape data using a little-known method. The method is powerful because it only requires a few lines of code and doesn't require any installation or browser.
    Free Excel VBA Resources
    Excel VBA Articles (excelmacromastery.com/vba-art...)
    Useful VBA Shortcut Keys
    ========================
    Debugging:
    Compile the code: Alt + D + L OR Alt + D + Enter
    Run the code from the current sub: F5
    Step into the code line by line: F8
    Add a breakpoint to pause the code: F9(or click left margin)
    Windows:
    View the Immediate Window: Ctrl + G
    View the Watch Window: Alt + V + H
    View the Properties Window: F4
    Switch between Excel and the VBA Editor: Alt + F11
    View the Project Explorer Window: Ctrl + R
    Writing Code:
    Search keyword under cursor: Ctrl + F3
    Search the word last searched for: F3
    Auto complete word: Ctrl + Space
    Get the definition of the item under the cursor: Shift + F2
    Go to the last cursor position: Ctrl + Shift + F2
    Get the current region on a worksheet: Ctrl + Shift + 8(or Ctrl + *)
    To move lines of code to the right(Indent): Tab
    To move lines of code to the left(Outdent): Shift + Tab
    Delete a Line: Ctrl + Y(note: this clears the clipboard)
  • Věda a technologie

Komentáře • 166

  • @Excelmacromastery
    @Excelmacromastery  Před 2 lety +23

    Learn how to write real-world Excel VBA code: 👉courses.excelmacromastery.com/
    Want to download the source code for this video? Go here: bit.ly/3NrfGt4

    • @viveksharma4193
      @viveksharma4193 Před 2 lety

      how to fetch data from sql

    • @lesliebenjamin5487
      @lesliebenjamin5487 Před 2 lety

      How can you handle say PAGINATED web data? same using VBA?

    • @sammybenmenahem
      @sammybenmenahem Před rokem

      But what if the page is not table elements, only divs and labels?

    • @vikrantchouhan9908
      @vikrantchouhan9908 Před 4 měsíci

      Hello sir, can one also load data on the html pages using the field ID (without relying on the sendkeys method). Any inputs will be valuable.

  • @bredmond812
    @bredmond812 Před 2 lety +15

    No kidding. I've been watching videos on VBA web scraping since yesterday and was going through CZcams literally right now looking for more getting ready for a project. Then you post this new video in the middle of that. Thank you!

    • @Excelmacromastery
      @Excelmacromastery  Před 2 lety

      That's Great Brandon.

    • @bredmond812
      @bredmond812 Před 2 lety

      @@Excelmacromastery Say, while I got your attention, do you know if it is feasable to capture a whole website and all its assets to make a copy of it?

  • @serdip
    @serdip Před 2 lety +2

    Another AMAZING video! Thanks very much for showing how easy it can be to scrape data from web pages. The solution presented is simple and elegant and easily adapted to a wide variety of use cases. Thank you!!

  • @redfeather22sa
    @redfeather22sa Před rokem +1

    Brilliant Paul !!! Thanks !! I've been using the same for years but glad there's an accessible reference to it on CZcams now !!

  • @AlejandroSerranoJuan
    @AlejandroSerranoJuan Před 2 lety +2

    Really. You are the best VBA code professor I know. As you keep sharing we keep improving. Thanks for it.

  • @CAP0NE
    @CAP0NE Před 9 měsíci

    Very good video and annotations. In about only 7 minutes I've learned more then in an hour of searching and reading.
    Many thanks for that!

  • @compscript7973
    @compscript7973 Před 2 lety +2

    This was great.
    I have been watching videos all day and this is the first one that worked.
    I look forward to watching this same video using other methods besides tables.

  • @jenniferbabitzke9474
    @jenniferbabitzke9474 Před rokem

    This video and code is going to save me countless hours on a research project. Thank you so much!!!

  • @cristiano440
    @cristiano440 Před rokem

    The most useful thing I've seen this year... man... you rock!

  • @stevennevin7466
    @stevennevin7466 Před 2 lety +1

    Excellent explanation. You have made this task much less daunting. 👏.

  • @alexandrumoldovan9936
    @alexandrumoldovan9936 Před 2 lety +1

    Great video with lots of insights, which is really the norm for Paul at this point.
    Query tables look really powerful, maybe you could make a video more in detail about it in the future. I'm sure many, myself included, would find that very helpful.
    Thank you!

  • @CanalInvestidor
    @CanalInvestidor Před rokem

    Excellent tutorial, makes it possible to explore many fronts.

  • @alanlamb6047
    @alanlamb6047 Před 2 lety +2

    Great video, well presented as always.
    As a long time excel user , I suspected this code was effectively the same as using the legacy data wizards
    (Data: GetData: Legacy Wizards: From Web. Note you may need to enable wizards: Excel Options: Data: Show legacy data import wizards: From Web)
    In some instances, I have found the legacy data connections are a lot faster than the modern PowerQuery methods
    Anyway, if you turn on the VBA recorder and then use the above wizard, you will get the same core VBA code generated as per the video
    However, in my quick performance check, the PQ method was substantially faster for this case

  • @HectorAgostoOne
    @HectorAgostoOne Před 2 lety

    Ahhh. This is excellent but I got so hooked to Power Automate for web scraping as it makes it sooo easy. Still, this tutorial is A+. Going to attempt this to have further hands on knowledge on vba

  • @hassanrozh6579
    @hassanrozh6579 Před 2 lety

    Great job, thanks for sharing this helpful way.

  • @MichaelWilliams-rf2jw

    I love this video! Thanks for sharing this info.

  • @free3690
    @free3690 Před 2 lety +3

    Very helpful examples, thank you for the video!

  • @Code___Play
    @Code___Play Před 5 měsíci

    Very practical and helpful video with very detailed explanation!

  • @joaocustodio2094
    @joaocustodio2094 Před 2 lety

    As always... well done Paul. Thanks very much.

  • @deexcelguy
    @deexcelguy Před 2 lety

    Mind-blowing... Best Web scrapping with VBA video ❤❤❤

  • @vikrantchouhan9908
    @vikrantchouhan9908 Před 2 lety +1

    Great one! Would it be possible to populate the data as well (on web pages) using this approach?

  • @dmp4096
    @dmp4096 Před 2 lety

    THIS!!! IS!!! AWESOME!!! I was looking for a way to let a workbook pull down data from a MySQL database on the web easily. I think with the right bit of code on my server I can make this happen with these tools.
    THANK YOU SO MUCH!

    • @jvdb5509
      @jvdb5509 Před 2 lety +1

      Have you tried using PowerQuery?

    • @dmp4096
      @dmp4096 Před 2 lety

      @@jvdb5509 no. I really am no Excel wizard. I’m an old school programmer trying to automate some stuff for a good friend and our ski race league. I’ve developed a bit of familiarity with VBA and this idea seems to get me around some other areas I have no familiarity with… LOL ….as well as not requiring total control over the server…

    • @Excelmacromastery
      @Excelmacromastery  Před 2 lety +1

      You're welcome

  • @KhalilYasser
    @KhalilYasser Před 2 lety

    Awesome tutorial. Thanks a lot.

  • @johnwayne8059
    @johnwayne8059 Před 2 lety +1

    Amazing video Paul!🥳🍀😁🤟😎

  • @TheMisiekMisiek
    @TheMisiekMisiek Před rokem

    Perfect. Very useful.

  • @turkaykoc8587
    @turkaykoc8587 Před rokem

    Thank you very much for sharing valuable information.

  • @danielmelo389
    @danielmelo389 Před 2 lety

    Best Excel channel on youtube

  • @derekharmon6999
    @derekharmon6999 Před 2 lety

    Great video! Would I be able to pull out all terms on a webpage that were bolded and list them on a column with this same code?

  • @vbaclasses3553
    @vbaclasses3553 Před 2 lety +1

    Great video, thanks for sharing. Another tool in the toolkit.

  • @CollDott
    @CollDott Před 2 lety +1

    👍 Amazing!!

  • @js-cx8wk
    @js-cx8wk Před 2 lety

    Thank you, nice video!!

  • @wojciechgebura3678
    @wojciechgebura3678 Před rokem

    You're doing great job, Paul, thank you! One question: is it possible to scrape Web Data with VBA the exact way as follows?
    I define about hundred URLs and also three to five keywords/phrases to find on those websites. VBA does the search job and when found, it returns the results in a spreadsheet as links to the articles that content those keywords/phrases. The process would be repeated once a week. Is it doable with the VBA?

  • @likhangsubok
    @likhangsubok Před 2 lety

    thank you so much for this tutorial, so helpful and very informative. watching from abu dhabi uae

  • @wayneedmondson1065
    @wayneedmondson1065 Před 2 lety

    Great one! Thanks Paul.

  • @postventatewis9968
    @postventatewis9968 Před 2 lety +6

    Great, Paul. Thanks for this. I want to ask you two questions. How send user & password to a site, and how populate the search box with a input box or a cell content.Regards

  • @apbosh1
    @apbosh1 Před 2 lety

    You're showing the chrome examples saying don't have to use all this code, I'm thinking that looks neat as, already. Superb information as usual. Do you have a video on reading larger csv files 250k rows but managing memory and cleaning up afterwards. I will look as well .

  • @golfmedic100
    @golfmedic100 Před 2 lety

    great video - just wondering if this method be used to scrape a table ?

  • @Jocedu06
    @Jocedu06 Před 2 lety

    Awsome! This is the object used by powerquery when loaded in a table

  • @ELS737
    @ELS737 Před 2 lety

    Tnak you for the Video, awesome! When I go to download stock quotes I only get updated data about once a minute, the sites seem to somehow prevent a second by second update. How would this still be possible?

  • @pbs36
    @pbs36 Před 2 lety

    Great video.

  • @meiyi6520
    @meiyi6520 Před rokem

    Great video! How do I write the code if I need to scrap the table from mulitple web pages?

  • @s1ngularityxd64
    @s1ngularityxd64 Před 2 lety

    This is so fast, amazing. How would you fetch urls from a table instead of a hard coded url?

  • @Victor-ol1lo
    @Victor-ol1lo Před 2 lety

    Awsome !! Thanks for sharing !!!

  • @Mexico0607
    @Mexico0607 Před rokem

    FIrst of all a very nice and useful tutorial. I have a practical question: I use the querytable approach. Unfortunately the webpage Table uses another number format then my Excel (. and , swapped for dezimals). Is it possible to change this in the querytable?

  • @todddean7722
    @todddean7722 Před 2 lety

    Can this method be used to navigate to other pages using links and to enter information needed, like login and passwords? If so, have you done a video on it? If so, may I get a link to the video? Thank you.

  • @miless2111sutube
    @miless2111sutube Před 2 lety +1

    as always presented in a clear, easy and reassuring way :) How do you know which table reference (table 1) to use? Is it simply counting them visually or is there somewhere on the web page that you have to go to see that the table is referenced as table 1?

    • @Excelmacromastery
      @Excelmacromastery  Před 2 lety +2

      No clear cut way. You can count them on the page but it's not always obvious what is a table. You can check the underlying html code. The easiest thing is to run the code until you hit the correct one although this may not always be feasible.

  • @user-ue9rh3xi3n
    @user-ue9rh3xi3n Před rokem

    Thanks Paul. This video is very helpful. You should be canonized for your body of work.

  • @micheltw
    @micheltw Před 2 lety

    Best web scraping video

  • @knowledge2excel83
    @knowledge2excel83 Před 2 lety

    Excellent

  • @KhanhNguyen-bn4jx
    @KhanhNguyen-bn4jx Před 2 lety

    thank you very helpful video.

  • @mustafakurt3546
    @mustafakurt3546 Před 2 lety

    perfect bro

  • @fortak2006
    @fortak2006 Před rokem

    this video is amazing, I used to use httprequest, how about if the website required login name and pw, is it possible use "query table"? thank you

  • @Donkeys_Dad_Adam
    @Donkeys_Dad_Adam Před 2 lety

    Could this method be used to grab a JWT (*Jason Web Token) from an Azure Database for use in running a Single Sign On process?

  • @orhanozturk1183
    @orhanozturk1183 Před 2 lety +2

    Hi, if web site is protecting like How to add username and password entering code?

  • @user-vg1zf8dn5m
    @user-vg1zf8dn5m Před 3 měsíci

    Hello, thank you for the video. I need help, please
    What should we do?
    If the site requires you to log in first, then scrape the data from it after that

  • @jennilong7798
    @jennilong7798 Před rokem

    Is there a way to use the whole page code, but using a large list of URLs and placing their data into new sheets? 1 URL = 1 new sheet.
    I need to do this for a large amount of URLs and can't figure out how to do it in batches/more than one at a time.

  • @softwareinfacont4438
    @softwareinfacont4438 Před 11 měsíci

    Hi. Excelent
    is it posible insert into MS ACCESS Table ?

  • @s1ngularityxd64
    @s1ngularityxd64 Před 2 lety

    always a pleasure

  • @user-nz1of4kh6u
    @user-nz1of4kh6u Před rokem

    Hello, good evening, wow, excellent tutorial. I have tried the macros and they work wonderfully, but something strange happens to me and I have not been able to find what is happening.... I perform a scraping to a web whose unique table has more or less 15000 objects but it only reflects me in the sheet only 100 .... What could be happening? I hope you help me understand thank you very much...

  • @jacobnye4490
    @jacobnye4490 Před rokem

    Does this work for dynamic web pages?

  • @CoolAmyKid
    @CoolAmyKid Před rokem

    how would I edit this code to just get one element from the webpage? preferably by ID
    thank you

  • @hjiraoussama776
    @hjiraoussama776 Před 2 lety

    Is there a way to scrape data from multiple salary pdf payslips into excel table ?

  • @superyngo
    @superyngo Před 2 lety

    Super!

  • @Irfan9191111
    @Irfan9191111 Před 2 lety

    There is a QUERY function in google sheets. Any such option in Excel (including VBA)?

  • @Szajbus37
    @Szajbus37 Před 2 lety

    Hi i just have a quastion about some help in my excel to automate a few steps, it's any chance to contant you ? Like discord or something else

  • @bxyhxyh
    @bxyhxyh Před 2 lety +1

    Hello, can you make a video to get unique values fastest way?
    - Dictionary way
    - Collection way
    - Unique function from 365 and 2021
    and other methods that i don't know etc...

  • @youknowme6780
    @youknowme6780 Před rokem +1

    I am working on a vba to fill web form, it works on first IE page and submit the form, but when a new page loads with different web address, my code don't recognize the active web page... Any advice??? No selenium used

  • @Space.of.C
    @Space.of.C Před rokem

    If there are multiple tables on the website then how can I extract let say 1-5 tables ??

  • @raviprakashh
    @raviprakashh Před rokem

    Can you please suggest how to send data to web page and click on button.

  • @rogerramos6745
    @rogerramos6745 Před 2 lety

    I am trying to download the Query Table source code but I get stuck on an infinite loading screen. Is there a better way to get around this? As it stands right now the code generates an error saying "Incomplete Database"

  • @huonggiang537
    @huonggiang537 Před 2 lety

    In case login requires captcha code, it is very difficult to pass this code, is there a way to scrape data from the website that is already logged in? Thank you very much

  • @torbjornsvensson2527
    @torbjornsvensson2527 Před 2 lety

    Nice Video! But I get the response that I have to Enable javascript from the webpage I try to scrape? Is there any solution for this?

  • @mmbcampus
    @mmbcampus Před rokem

    hello, How can i interact or populate a webpage form through VBA MSXML without opening IE or without IE method. pls kindly help?

  • @cacinaz8802
    @cacinaz8802 Před 2 lety

    Incredible! Thank you. When I call up Yahoo! historical stock data, the date parameters are set to today's date and then back one year. Is there a way to set the date parameters differently?

    • @Excelmacromastery
      @Excelmacromastery  Před 2 lety

      It may be possible if the parameters are in the url. otherwise you'll need to use either Chrome Selenium or XMLHttp.

  • @garyburke9990
    @garyburke9990 Před rokem

    Would be great if you could do a video on scraping an e-commerce site

  • @Donly1pt
    @Donly1pt Před 2 lety

    Excellent work. One question, is there a way to make the code wait for the query to complete before proceeding? Using that "Main" sub you used on the video as an example, if I have code after the UseQueryTable to do something with the values that I expect from the table it will try to do so before the table is there because the query takes a while. I tried using a Sleep function after the UseQueryTable call but it seems to also halt the progress of query....

    • @pjetrucha
      @pjetrucha Před 2 lety

      Had the same issue with macro which refreshed tables in Excel (connected to Oracle database through PowerQuery) and later used those tables in some calculations. I've tried Sleep, Wait but it didn't fit my needs. Finally I've stumbled upon DoEvents and it worked like a charm ;)

    • @Donly1pt
      @Donly1pt Před 2 lety

      @@pjetrucha how could I use doevents in this case to allow the query to complete?

  • @jim2lane
    @jim2lane Před 2 lety +1

    For those who are fairly new to coding, what you see there in the VBA coding window is the development environment that all Microsoft centric coders worked in twenty years ago 😊

    • @FilipCordas
      @FilipCordas Před 2 lety

      Don't be ridiculous Visual Studio has been introduced in 2000 and it was by far the best ide in the world.

    • @jim2lane
      @jim2lane Před 2 lety +1

      @@FilipCordas actually, the first version of VS came out in '97. I used that version extensively back then, and each iteration since then. But the IDE experience back then was very similar to this - hence my comment

    • @stevenabel2068
      @stevenabel2068 Před rokem +1

      @@jim2lane I still have a copy of Visual Basic 1.0 - those were the days. Bleeding edge programming and boy were we bleeding at times

  • @mannymtzgomez
    @mannymtzgomez Před rokem +1

    I can’t seem to get the code files, could you please post them again?

  • @juniorortizaraujo6139
    @juniorortizaraujo6139 Před 9 měsíci

    Can we download excel report from a website ??

  • @online7198
    @online7198 Před 5 měsíci

    Hello, I am Omar from Egypt. I am interested in your videos. I would like to ask a question. Can I access a data source for a website.
    When I search about some on website

  • @normalguystrive
    @normalguystrive Před rokem

    Anyone know if this can be used on a webpage with a username and password? IE, not public, but it's my account that I log into.

  • @geoffj3191
    @geoffj3191 Před rokem +1

    This is great, but how do you login and submit your username and password before you access the data. I can enter my username and password, but can't figure out how to click on the button as it doesn't seem to be clearly identifiable in the HTML.

  • @rafatshaikh3599
    @rafatshaikh3599 Před 2 lety

    Hi, I want to scrap Indimart Data. There are no options for exporting the data. I want the leads available for the specific category. I have the API as well. Please can you guide me on this

  • @gzfraud
    @gzfraud Před 11 měsíci

    QUESTION .... I scrape 10,00+ webpages so this will really help. BUT if a URL is embedded in text on a webpage, PQ or BI won't extract the URL eg email address is embedded in the person's name. I've searched and can't find it. Any ideas?

  • @cristhiancabra184
    @cristhiancabra184 Před 2 lety

    Hello, excellent video, but i have a question, what if we need to get data from a webpage that isn't in a table and we need to find the html location? Can you make a video explaining that webscraping method please? how to extract specific data from a webpage

    • @mirekt1822
      @mirekt1822 Před 2 lety

      Look at 5:42 there is some info but it needs some learning ;-)

  • @bigdatax6512
    @bigdatax6512 Před rokem

    is working for 100 pages??or just one page???

  • @vincentblackwall8645
    @vincentblackwall8645 Před 2 lety

    I have a question - how I can we scrape using your method, in case if I need scrape multiple tables from the different pages?

    • @Excelmacromastery
      @Excelmacromastery  Před 2 lety

      You would use the AfterRefresh event to detect when the QueryTable Refresh was complete(see docs.microsoft.com/en-us/office/vba/api/excel.querytable.afterrefresh)

  • @suqabi
    @suqabi Před rokem

    It give me error massage : unable to open "url". Cannot download the information requested.

  • @ignacioa3698
    @ignacioa3698 Před 2 lety

    You able to do webscrape, however, scraping data from the page filters that I normally have to MANUALLY populate the search criteria? For example, I have to get just simple total numbers of times a particular person’s username processed certain items for the day.
    I have to do this for about 10 different users from my team at work. And I have to pull the data by manually populating that person’s username in the specific search filter field criteria then the page clocks and spits out the data table, then I manually highlight the data on the page in order to get a simple total number of times that come up for that specific username for the day. And I have to type and change the username on a specific filter search space every time for all of my work group members that I’m collecting the data.
    Also, depending on how long it takes the page to get the data, I know there’s a VBA feature that prevents the VBA from “timing out” in case the data at times takes longer depending on the size the data table.

  • @vivandh1404
    @vivandh1404 Před 10 měsíci

    sir how can we achieve IMPRTXML FUNCTIONALITY of google sheet into MS excel ?

  • @Malignvs
    @Malignvs Před 2 lety

    Did you test Selenium recently, though? I can't make it work. Probably because the library wasn't updated since 2016... I wrote a lot of automations for IE and I am looking for a replacement (since IE is going to be discontinued soon). Your method is cool, but my automations are focused on executing scripts, clicking buttons and inputting data into boxes.

    • @FilipCordas
      @FilipCordas Před 2 lety

      Selenium should work fine for scraping how are you running it headless or browser? Have you checked Power Automate you can do a lot using the desktop version?

    • @Malignvs
      @Malignvs Před 2 lety

      @@FilipCordas For me Selenium fails at the driver.Start command. I tried with both Edge and Chrome. Yes, Power Automate is one solution, Python is another. Not having an ability to install whatever you want on your work laptop due to company policy is a problem, however.

    • @FilipCordas
      @FilipCordas Před 2 lety

      @@Malignvs What version of Selenium driver do you have? Python is not a solution it's a programming language a bad one at that, but I find it strange that they would allow you to install python sdk, ide and selenium drivers for python rather than power automate that comes native in windows 11 that's the reason I recommend it you might have it already, but it could be the case corporate IT is usually ridiculous.

  • @AvagyanAvag
    @AvagyanAvag Před 2 lety

    Nice coding example, although for this job Power Query suits better

  • @klent3284
    @klent3284 Před 2 lety

    The link for the source code doesn't seem to work. Getting this error: "This site can’t be reached"

  • @davej429
    @davej429 Před 2 lety

    Promising but after putting this in and running, it is just so very slow to pole the site and write the data. Not sure anything can be done to speed up. I'm using Windows 10 and Office 365.

  • @didierseverac
    @didierseverac Před 2 lety

    When you delete the table doesn't that breaks all the formulas that were using it ?

    • @Excelmacromastery
      @Excelmacromastery  Před 2 lety

      Yes. If you want to simply update a table you can use Refresh once the table is created.

  • @phanhuyhoang3720
    @phanhuyhoang3720 Před 2 lety

    I’m stuck with f2a even I knew all credentials. Any Idea sir

  • @salvatoreimperatore9553

    Hello, compliments, I would like to ask you if you think it is possible to create a vba for Google search. I would need to enter a barcode on the Excel sheet and through the search of the code it should return me product name, brand, description, and image link. Is something like this possible? It would be great if you could make a video for it. I think it would be interesting for all traders like me who have a physical store and an online site and each time uploading products to the site is boring because it involves thousands of product sheets, so if we could manage to search through the barcode product on the web and returns: product name, description, brand, and 3-4 product image links in an excel sheet to then upload the sheet to the site. Would be the best. Let me know if this idea of ​​mine is possible or impossible, thank you

  • @samektahadi
    @samektahadi Před rokem

    "needs to review the security of your connection before proceeding"
    hi, I got this message when running the vba code you're providing

  • @wikanwiratmoko4446
    @wikanwiratmoko4446 Před 8 měsíci

    helo sir, how scrape data from registeried page ?

  • @TP-om8of
    @TP-om8of Před 2 lety +2

    It’s definitely better than the old IE method. But seriously, use Python not VBA for webscraping

    • @Excelmacromastery
      @Excelmacromastery  Před 2 lety +4

      Maybe for extensive web scraping. But if you just need to get data from a page or table then installing and learning Python is a big overhead for most people.