From the course: Python-Powered Excel: Boost Your Excel Productivity with the Power of Python by Microsoft Press
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Demo: Create a scrape custom function
From the course: Python-Powered Excel: Boost Your Excel Productivity with the Power of Python by Microsoft Press
Demo: Create a scrape custom function
All right. So now that we've seen how to take data that's on a website and create an Excel file from it, what I'd like to do is show you how to rewrite this a little bit so that you don't have to rewrite all of this code that we have here for each and every site that you want to scrape data from. So essentially, what we're going to do is we're actually going to create a Python function where we'll just be able to say something like, maybe we'll call it scrape_to_excel. All right. And we'll just give it a URL. So whatever site you want to scrape data from, I'll just say blah, for now, just while I'm demonstrating what this is going to look like, of course. And then the second argument here is going to be a dictionary containing all of the column titles and selectors for the data from those columns. So, for our purposes right here, it might look like this. We could say description, and the selector for that would be p.description, okay? So we've said p.description, and then we could do…