Latest / Talk Python To Me / #283: Web scraping, the 2020 edition
Transcript
- 0:00Web scraping is pulling the HTML of a website down and parsing useful data out of it.
- 0:04The use cases for this type of functionality are endless.
- 0:07Have a bunch of data on governmental sites that are only listed online in HTML without a download?
- 0:13There's an API for that.
- 0:15Do you want to keep abreast of what your competitors are featuring on their site?
- 0:19There's an API for that.
- 0:20Need alerts for changes on a website?
- 0:23For example, enrollment is now open at your college,
- 0:26and you want to be first and avoid that 8 a.m. morning slot?
- 0:29Well, there's an API for that as well.
- 0:31That API is Screen Scraping, and Attila Toth from Scraping Hub is here to tell us all about it.
- 0:36This is Talk Python To Me, episode 283, recorded July 22, 2020.
- 0:41Welcome to Talk Python To Me, a weekly podcast on Python,
- 0:58the language, the libraries, the ecosystem, and the personalities.
- 1:00This is your host, Michael Kennedy.
- 1:02Follow me on Twitter, where I'm @mkennedy.
- 1:05Keep up with the show and listen to past episodes at talkpython.fm,
- 1:08and follow the show on Twitter via at Talk Python.
- 1:11This episode is brought to you by Linode and us.
- 1:15Python's async and parallel programming support is highly underrated.
- 1:20Have you shied away from the amazing new async and await keywords because you've heard it's
- 1:24way too complicated or that it's just not worth the effort?
- 1:27With the right workloads, a hundred times speed up is totally possible with minor changes to your code.
- 1:33But you do need to understand the internals, and that's why our course,
- 1:36Async Techniques and Examples in Python,
- 1:38show you how to write async code successfully as well as how it works.
- 1:44Get started with async and await today with our course at talkpython.fm/async.
- 1:49Attila, welcome to Talk Python To Me.
- 1:52Thanks for having me, Michael.
- 1:53Yeah, it's great to have you here.
- 1:55I'm looking forward to talking about web scraping.
- 1:57It's the API that you didn't know it exists,
- 2:01but it's out there if you're willing to find it.
- 2:02It's like the dark API.
- 2:03Yeah, it's like a secret API that you need a little work
- 2:07to sort of like be able to use it, to earn the right to use it.
- 2:11Yeah.
- 2:12But yeah, I like it.
- 2:13It's useful.
- 2:14It definitely is.
- 2:15And we've got some pretty interesting use cases to talk about
- 2:18and a little bit of history and stuff.
- 2:20I'm obviously going to talk about Scrapey,
- 2:21some stuff about Scraping Hub, what you guys are doing there.
- 2:24So a lot of fun stuff.
- 2:25But before we get to all that, let's start with your story.
- 2:27How'd you get into programming in Python?
- 2:28Yeah, sure.
- 2:29So actually, I got into programming back in elementary school.
- 2:33I was the sort of kid, I think I was like eighth grade.
- 2:37And at the time, everybody in my class in school,
- 2:40everybody was asking for like,
- 2:42I think it was Xbox 360 that just came out.
- 2:46Everybody was asking for that for Christmas.
- 2:48Yep.
- 2:49And I was the one who was asking for a book about programming.
- 2:54What language did you want at that time?
- 2:56Yeah.
- 2:57So actually, I did like a lot of research.
- 3:00I think for like three months,
- 3:02I was researching which programming language is the best for beginners.
- 3:07So I was on different forums, Yahoo Answers,
- 3:11in every place on the internet.
- 3:13And many people suggested at the time, Pascal.
- 3:16So I got this book.
- 3:18I think it was called something like
- 3:20Introduction to Turbo Pascal or something like that.
- 3:23Right.
- 3:24Okay.
- 3:24Yeah.
- 3:25So I got the book.
- 3:26And that was the first step.
- 3:28And then after like 40 pages into the book,
- 3:31I threw it away because I found that just Googling stuff,
- 3:35Googling stuff in Google and Stack Overflow,
- 3:38it's just easier to learn it that way.
- 3:41Nice.
- 3:42So did you end up writing anything in Turbo Pascal?
- 3:45Yeah.
- 3:46I was just, you know,
- 3:47the regular things beginners usually do.
- 3:49Like in the terminal,
- 3:51I, you know,
- 3:52I printed my name in red.
- 3:54I printed like figures with characters,
- 3:58you know,
- 3:58just the regular things beginners do.
- 4:00But then I quickly switched to Java after Pascal.
- 4:04Right.
- 4:05Java, you can build web apps,
- 4:07you can build GUIs,
- 4:08more interesting things.
- 4:10Yeah.
- 4:10At the time I was interested in Android,
- 4:13Android development.
- 4:14Actually,
- 4:15it was a few years later when I got to high school,
- 4:18I started to like program in Java to develop Android apps.
- 4:22I created like,
- 4:24I don't know,
- 4:24maybe like five or six apps for Google Play that I just found useful,
- 4:30like minor things like a music player that plays music randomly,
- 4:35which there are on your phone.
- 4:37And the only input is how long you want to listen to music.
- 4:41Oh, cool.
- 4:41So I was like,
- 4:42I want to listen for 20 minutes.
- 4:44And they just randomly plays music for 20 minutes.
- 4:47So, you know,
- 4:48little things like that.
- 4:49Yeah.
- 4:49Cool.
- 4:50How'd you find your way over to Python?
- 4:51Thanks to,
- 4:52thanks to web scraping actually.
- 4:54Yeah.
- 4:54Yeah.
- 4:55You know,
- 4:56I'm not sure which was the first point.
- 4:58No,
- 4:59I actually remember which was the first time I came across web scraping.
- 5:02I was trying to develop like a software.
- 5:06Like I was pretty into sports betting,
- 5:08football and soccer.
- 5:09And I didn't play high stakes because I wasn't that good to afford to do it.
- 5:16But I was interested in the analysis part,
- 5:18you know,
- 5:19looking up stats,
- 5:20looking up injury information,
- 5:22looking at different factors that would determine the result,
- 5:27the outcomes of games.
- 5:28And I wanted to create a software that would predict the outcome of these games or some of the,
- 5:36we have,
- 5:36I don't know,
- 5:3725 games in a weekend.
- 5:38And it would predict the like,
- 5:41okay,
- 5:41look at these three games.
- 5:43And these are going to be the results.
- 5:45So I wanted to create a software like this.
- 5:47Right.
- 5:48And if that beats the spread that they are offering at Las Vegas,
- 5:51you're like,
- 5:51oh,
- 5:51they're going to win by 14.
- 5:53Oh,
- 5:53they said they're only winning by seven.
- 5:55I want to take that.
- 5:56Maybe.
- 5:56Yeah.
- 5:57I tried that.
- 5:58And I also tried.
- 5:59How did it go?
- 6:00Yeah.
- 6:03Well,
- 6:03the thing is,
- 6:04I wouldn't say it went too good,
- 6:06but it wasn't too bad.
- 6:07I mean,
- 6:08I experimented,
- 6:09like,
- 6:10first of all,
- 6:11I was betting on like over and under,
- 6:12because I found that that's like a more predictable thing to bet on.
- 6:17That's what I thought,
- 6:19because in reality,
- 6:20it isn't,
- 6:20but I bet on over and under.
- 6:22And so this software would tell me that,
- 6:25hey,
- 6:26in this game,
- 6:27you know,
- 6:27if it's soccer,
- 6:29there will be more than two goals in the first half.
- 6:33And so what I would do is I would watch the game live,
- 6:38because in life,
- 6:39there are better odds,
- 6:40because as the time progresses,
- 6:42the odds for scoring the first half goes up.
- 6:45So I just waited for like the,
- 6:47I think it was the 15th minutes or something like that.
- 6:50And if there is still no goals scored in the first half,
- 6:54I would bet on it.
- 6:55So I was doing this for like,
- 6:57I think four months without money,
- 7:00just testing the system.
- 7:01Right.
- 7:02I was watching and okay,
- 7:03I would bet right now.
- 7:05And I was calculating,
- 7:06I had this Excel spreadsheet and everything.
- 7:08And in that four months period,
- 7:10I was just,
- 7:11I think it was not profitable at all,
- 7:14but it was close to being just a little profitable long term.
- 7:19Yeah.
- 7:19Well,
- 7:20maybe you were onto something.
- 7:21If you get some more factors,
- 7:22maybe bring in a little machine learning,
- 7:24who knows?
- 7:25Yeah,
- 7:26actually,
- 7:26maybe I should pick it up.
- 7:28But that's when I came across web scraping.
- 7:30Right.
- 7:31Because I needed data.
- 7:33I needed stats.
- 7:34And a lot of these places,
- 7:35they don't want to give out that data.
- 7:37They'll show it on their website,
- 7:38but they're not going to make an API that you can just stream.
- 7:40Right.
- 7:41Exactly.
- 7:42At the time,
- 7:43there were like different commercial APIs that big news corporations use,
- 7:50but it was just a hobby project.
- 7:51And the only way for me to get data was to extract it from a publicly available website.
- 7:59And so I started to look into it.
- 8:02And at the time I was programming in Java.
- 8:04So I found Jsoup.
- 8:06I found HTML unit,
- 8:08which is a testing library,
- 8:11but it can be used for web scraping.
- 8:12I found,
- 8:13is it Jount?
- 8:15I think it's pronounced Jount.
- 8:16And I found other libraries.
- 8:19And everybody was saying that,
- 8:21which one is the best?
- 8:22Which one is the best?
- 8:23Everybody was talking on the forums about Scrappy.
- 8:26And I didn't know what Scrappy was.
- 8:28So I looked it up.
- 8:29It's in Python.
- 8:30I don't know how to program in Python.
- 8:32I barely can program in Java.
- 8:34But then I eventually learned Python just to learn Scrappy.
- 8:39Cool.
- 8:40Yeah.
- 8:40And it's such a nice way to do web scraping.
- 8:42It's a weird language.
- 8:44It's Python.
- 8:45It doesn't have semicolons,
- 8:46curly braces.
- 8:47There's not so many of those.
- 8:49Yeah.
- 8:49It was like comparing it to Java.
- 8:51It's very clean.
- 8:53Yeah.
- 8:53That's for sure.
- 8:54Java is a little verbose in all of its type information,
- 8:57even for a typed language,
- 8:58like say compared to C or I don't know,
- 9:01maybe even C#.
- 9:02Like it likes its interfaces and all of its things and so on.
- 9:06Right.
- 9:06Yeah.
- 9:07The best thing I love about Python,
- 9:09which I cannot do in Java,
- 9:10is that in Python,
- 9:11you can read the code like an actual sentence.
- 9:15Right.
- 9:16I mean,
- 9:16not always,
- 9:16but sometimes you can,
- 9:18it's like a sentence.
- 9:19Yeah.
- 9:19There's this cartoon joke about Python that there's these two scientists or something like that.
- 9:26And they've got this pseudocode.
- 9:28It says pseudocode on their file.
- 9:29And it's like pseudocode.txt.
- 9:31They're like,
- 9:32oh,
- 9:32how do we turn this into a program?
- 9:34Oh,
- 9:34you change the txt to a .py and it'll run.
- 9:36Yeah.
- 9:37It's already there.
- 9:38Yeah,
- 9:39exactly.
- 9:39All right.
- 9:40Well,
- 9:40so that's how you got into it.
- 9:42And obviously your interest in web scraping.
- 9:44So,
- 9:44you've continued that interest today,
- 9:47right?
- 9:47What are you doing these days?
- 9:48Yeah.
- 9:49So I've been developing like a lot of spiders,
- 9:52a lot of scrapers with Scrappy and other tools over the years.
- 9:55And nowadays I joined the company who actually created Scrappy,
- 10:00Scraping Hub.
- 10:01And I'm with Scraping Hub for over a year now.
- 10:04And what I'm doing is as a day-to-day is educating people about web scraping,
- 10:09both on the technical side of things and business side of things,
- 10:13like how to extract data from the web,
- 10:16why is it useful for you or why it can be useful for you.
- 10:20And so nowadays I don't really code that much unless it's for
- 10:25an article or a tutorial or to showcase some new stuff.
- 10:29I spend more time on creating videos and just,
- 10:33you know,
- 10:33teaching.
- 10:34Yeah.
- 10:34Well,
- 10:35that sounds really fun.
- 10:35You just get to explore,
- 10:36right?
- 10:37Yeah.
- 10:37And the biggest part or the best part I love about it is that like,
- 10:42I get to speak to customers who are doing web scraping or who are sort of
- 10:47enjoying the benefits of web scraping.
- 10:49And there are some really cool stories,
- 10:53like what these customers do with data.
- 10:55Yeah.
- 10:56And it's really creative.
- 10:57Like people can get super creative,
- 11:00like how to make use of,
- 11:01you know,
- 11:02web data,
- 11:02which is like,
- 11:03it's in front of you.
- 11:05You can see the data on your website.
- 11:06It doesn't look like interesting or like,
- 11:09you know,
- 11:09but when you extract it and you structure it,
- 11:12you can actually make use of it and drive,
- 11:15you know,
- 11:15you can do many different things,
- 11:17but you can drive better decisions in companies,
- 11:20which is pretty exciting.
- 11:21Yeah.
- 11:22And I guess if you work at a company and you're looking to think about,
- 11:26I'd like to do some comparative analysis against say our competitors and what
- 11:31are they doing?
- 11:32What are they doing with sales?
- 11:33Like in terms of discounts,
- 11:35what are they doing in terms of things are featuring,
- 11:37right?
- 11:38You could theoretically write a web scraper that looks at your competitors'
- 11:42data,
- 11:43their sites,
- 11:44their presentation,
- 11:44and sort of gives you that over time relative to you,
- 11:48right?
- 11:48Or something like that.
- 11:49Yeah.
- 11:50Like many use cases are,
- 11:54you know,
- 11:54as you said about monitoring competitors or monitoring the market.
- 11:59And especially it's a big thing in e-commerce where most of the sectors in e-commerce are
- 12:06really like,
- 12:08there are a lot of companies doing the same thing,
- 12:10selling the same thing.
- 12:12And it's just really hard for them to sell more products.
- 12:16So with web scraping,
- 12:18they can monitor the competitor prices.
- 12:21They can monitor the competitors' stock information.
- 12:25They can monitor pretty much everything that is on their website,
- 12:29publicly available.
- 12:31And they can gather this information.
- 12:33And,
- 12:34you know,
- 12:35it can be like tens of thousands of products or more.
- 12:38And you can see where you should raise your prices,
- 12:42lower your prices,
- 12:43and how to price your products better and do marketing better.
- 12:49Yeah.
- 12:50And there's a lot of implicit signals as well that are not,
- 12:52you know,
- 12:53they're not most companies.
- 12:54Some do,
- 12:55but most won't go,
- 12:56there are 720 of these sold today or whatever.
- 12:59Yeah.
- 13:00but you could say graph,
- 13:01like the number of reviews over time or the number of stars over time,
- 13:06things like that would give you a sense of like a proxy,
- 13:09that kind of information.
- 13:10Right.
- 13:10you could come up with a pretty good analysis and pretty interesting analysis.
- 13:13This portion of Talk Python To Me is brought to you by Linode.
- 13:18Whether you're working on a personal project or managing your enterprise's infrastructure,
- 13:22Linode has the pricing,
- 13:24support,
- 13:24and scale that you need to take your project to the next level.
- 13:27With 11 data centers worldwide,
- 13:29including their newest data center in Sydney,
- 13:31Australia,
- 13:32enterprise-grade hardware,
- 13:34S3 compatible storage,
- 13:35and the next generation network,
- 13:38Linode delivers the performance that you expect,
- 13:40at a price that you don't.
- 13:42Get started on Linode today with a $20 credit,
- 13:45and you get access to native SSD storage,
- 13:47a 40 gigabit network,
- 13:49industry-leading processors,
- 13:50their revamped cloud manager,
- 13:52cloud.linode.com,
- 13:53root access to your server,
- 13:55along with their newest API,
- 13:56and a Python CLI.
- 13:58Just visit talkpython.fm/Linode
- 14:01when creating a new Linode account,
- 14:03and you'll automatically get $20 credit for your next project.
- 14:06Oh, and one last thing,
- 14:07they're hiring.
- 14:08Go to linode.com slash careers,
- 14:10to find out more.
- 14:11Let them know that we sent you.
- 14:15also, like, some of the things that people monitor with web scraping
- 14:18is more like higher level.
- 14:20We have the price, stock,
- 14:22but those are, like, really specific things,
- 14:25or values.
- 14:26But with web scraping,
- 14:27you can actually monitor, like,
- 14:29company behaviors,
- 14:30what the company is doing on a high level.
- 14:33And you can achieve this by monitoring news,
- 14:36looking for, like,
- 14:38the text,
- 14:39or the blog of the company,
- 14:41and getting out some useful information from that.
- 14:45And, you know, setting up alerts and things like that.
- 14:47Yeah, yeah, super cool.
- 14:48So there's a couple of examples that I wanted to
- 14:51put out there,
- 14:52and then get your thought on it.
- 14:54One is, you know,
- 14:56most of the world has been through the ringer on COVID-19
- 14:59and all of this stuff.
- 15:00In the U.S.,
- 15:01we definitely have been recently getting our fair share of
- 15:04disruption from that.
- 15:05So there's an article on
- 15:07towardsdatascience.com
- 15:08where some,
- 15:10the challenge was that
- 15:12in the early days of the lockdowns,
- 15:15at least in the United States,
- 15:16we had things like Instacart
- 15:18and other grocery delivery things,
- 15:19like there's local grocery stores,
- 15:21you could order stuff
- 15:23and they would bring it to your car outside
- 15:25so you didn't have to go in,
- 15:26other people,
- 15:27fewer people in the store,
- 15:28all sorts of stuff
- 15:29that was probably a benefit from that.
- 15:30But if you tried to book it,
- 15:32it was like a week and a half out.
- 15:34Yeah.
- 15:34And it was,
- 15:35it was a mess, right?
- 15:36And so this person,
- 15:38as they wrote it,
- 15:39Emmy GIL wrote this article
- 15:41that talked about using web scraping
- 15:44to find a grocery store delivery slots, right?
- 15:48So you could basically say,
- 15:49I'm going to go to my grocery store
- 15:50or to like something like,
- 15:51Instacart
- 15:52and I'm just going to watch
- 15:53until one of these slots opens up.
- 15:55And then what he had to do
- 15:57was actually send him a text,
- 15:58like go now and book it,
- 15:59place my order now or whatever.
- 16:01And I think that that's a really creative way
- 16:04of using web scraping.
- 16:05What do you think?
- 16:06Yeah, it's definitely really creative.
- 16:08It's useful.
- 16:09So he wasn't just only getting alerted
- 16:13when there's a new spot available,
- 16:14but he actually created the bot.
- 16:16So it like,
- 16:17it chooses that spot.
- 16:18Right.
- 16:19It would actually place the order.
- 16:21Yeah, that's smart.
- 16:21I mean, there are,
- 16:22we had the same situation in Hungary
- 16:25where you couldn't find any free spot.
- 16:28And the thing I love about web scraping
- 16:30is that it can be useful
- 16:32for huge companies
- 16:34to do web scraping at scale,
- 16:37but it can be also useful
- 16:38for literally everyone.
- 16:40Yeah.
- 16:40In the world,
- 16:41just doing little things like this.
- 16:43I have a friend who is looking
- 16:45to buy an apartment
- 16:46and currently the real estate market
- 16:49is really like fragile,
- 16:50I would say.
- 16:51Yeah, yeah.
- 16:52Yeah.
- 16:52And what he wants to do
- 16:54that I suggested him to do it
- 16:56is to create,
- 16:57set up a bot
- 16:58that monitors
- 16:59like 10 websites,
- 17:0110 real estate listing websites.
- 17:04And so he will get alerted
- 17:06when there is a apartment available
- 17:09with the attributes
- 17:11he's interested in.
- 17:12Right.
- 17:13Okay.
- 17:13That's awesome.
- 17:14Yeah.
- 17:14So there are so many
- 17:17little things like this
- 17:18in web scraping
- 17:19and it's just awesome.
- 17:21Yeah, I agree.
- 17:21People talk often
- 17:23about this concept
- 17:24popularized by Al Swigert,
- 17:25like automate the boring stuff.
- 17:27Like, oh, I got to always
- 17:28do this thing in Excel.
- 17:29So could I write a script
- 17:30that just generates
- 17:30the Excel workbook
- 17:32or I've always got to
- 17:33do this other thing,
- 17:34copy these files
- 17:34and rename them,
- 17:35write something that does that.
- 17:36But this feels like
- 17:37the automate the boring stuff
- 17:39of web interfaces,
- 17:40automate tracking
- 17:41of these sites
- 17:42and let it like finding out
- 17:44when there's a new thing.
- 17:45Yeah.
- 17:45Automate the boring stuff
- 17:46is a really good resource.
- 17:48In this case,
- 17:49it's really like
- 17:50what it's about.
- 17:51If you didn't create
- 17:52a web scraper for this,
- 17:54what you would do?
- 17:55You would probably
- 17:56look at the website
- 17:57every single,
- 17:58as often as you can,
- 18:00every day,
- 18:00every hour.
- 18:01You'd hear somebody say,
- 18:03I checked it every day
- 18:04until I found
- 18:04the apartment I wanted,
- 18:05right?
- 18:06That's what they would say.
- 18:07Yeah, exactly.
- 18:08Yeah.
- 18:09And what you don't hear
- 18:10them say so often is
- 18:11my bot alerted me
- 18:13when my dream apartment
- 18:14was available.
- 18:15Yeah.
- 18:15I created a scrappy spider
- 18:17that alerts me
- 18:18when there is a new
- 18:19apartment listing
- 18:20in that area.
- 18:21Yeah.
- 18:21And,
- 18:22but I think it's a really
- 18:24great example
- 18:24and it's like,
- 18:25there's so many things
- 18:26on your computer
- 18:27that you do
- 18:28that you kind of feel like,
- 18:28ah,
- 18:29this stuff I just got to do.
- 18:30But on the web,
- 18:30there's way more
- 18:31even that you probably end up,
- 18:33I always go to this site
- 18:34and then I do this thing
- 18:34and I got to do that,
- 18:35right?
- 18:35And web scraping
- 18:36will kind of open
- 18:37up a ton of that stuff.
- 18:39So,
- 18:39let me give you two examples.
- 18:41One,
- 18:42really grand,
- 18:43large scale.
- 18:44One,
- 18:44like,
- 18:45extremely small
- 18:45but like,
- 18:46really interesting to me
- 18:47in the next,
- 18:48you know,
- 18:48hour.
- 18:48So,
- 18:49grand scale first.
- 18:50When Trump was elected
- 18:52in the United States
- 18:532015
- 18:54and he was going to be
- 18:55come president
- 18:56in 2016,
- 18:57there was a lot of concern
- 18:58about what was going to happen
- 19:00to some of the data
- 19:01that had so far
- 19:02been hosted
- 19:02on places like
- 19:04whitehouse.gov.
- 19:05So,
- 19:05like,
- 19:05there's a lot of
- 19:06climate change data
- 19:07hosted there
- 19:08from the scientists
- 19:09and there was
- 19:10a thought
- 19:11that he might
- 19:12take that down,
- 19:13not necessarily destroy it,
- 19:14but definitely
- 19:15take it down
- 19:16publicly from the site
- 19:17and there's,
- 19:18you know,
- 19:18there's all these
- 19:18different places,
- 19:19the CDC
- 19:20and other
- 19:21organizations
- 19:22that have a bunch
- 19:23of data
- 19:23that a bunch
- 19:24of data scientists
- 19:25and other folks
- 19:27were just worried
- 19:28about.
- 19:29So,
- 19:29there were these
- 19:30big movements
- 19:30and I struggle
- 19:31to find the articles,
- 19:33you know,
- 19:33almost four years
- 19:34out now.
- 19:35Can't quite find
- 19:36the right search term
- 19:36to pull them up
- 19:37but there was these
- 19:38like,
- 19:38save the data
- 19:40hackathon type things.
- 19:42So,
- 19:42people got together
- 19:43at different universities,
- 19:44like 20,
- 19:4630 people
- 19:46and they would spend
- 19:47the weekend
- 19:48writing web scraping
- 19:49to go around
- 19:50to all these
- 19:50different organizations,
- 19:51download the data.
- 19:53I think they were
- 19:54coordinated across locations
- 19:55and then they would
- 19:56put that all
- 19:57in a central location,
- 19:58I think somewhere
- 19:59in Europe,
- 19:59like in Switzerland
- 20:00or something,
- 20:00so the data
- 20:01could live on.
- 20:02And I think
- 20:03the day that
- 20:04Trump was elected,
- 20:04I think the
- 20:05climate change data
- 20:06went off of
- 20:07whitehouse.gov.
- 20:07So,
- 20:08at least one
- 20:09of the data sources
- 20:09did disappear
- 20:10and that's
- 20:11a pretty large
- 20:12scale web scraping
- 20:13effort.
- 20:13Some of it was
- 20:14just like download
- 20:15CSVs,
- 20:15but a lot of it
- 20:16was web scraping,
- 20:16I think.
- 20:17Yeah,
- 20:17like the thing
- 20:19is people say
- 20:20that once
- 20:20you put something
- 20:21on the internet,
- 20:22it's going to
- 20:23stay there forever.
- 20:23And why
- 20:24this story is
- 20:25interesting is that
- 20:26this is information
- 20:27that is useful
- 20:29for everyone.
- 20:30Yeah.
- 20:30And this is the
- 20:31kind of information
- 20:32that you want
- 20:33to make publicly
- 20:34available.
- 20:35And I think
- 20:36this is one of
- 20:37the things that
- 20:37this movement
- 20:38is about,
- 20:39if I can call
- 20:40it movement,
- 20:40open data
- 20:41to make data
- 20:43open and accessible
- 20:44for everyone.
- 20:45And web scraping
- 20:47is really
- 20:48a great tool
- 20:50to do that,
- 20:50to extract data
- 20:52from the web,
- 20:53put it in a
- 20:54structured format
- 20:55in a database
- 20:56so you can use it,
- 20:58can just store
- 20:59information or you
- 21:00can get some
- 21:01kind of intelligence
- 21:02from the data.
- 21:03And it's really
- 21:04like without
- 21:05web scraping,
- 21:06what you couldn't
- 21:07do anything else.
- 21:08will you just
- 21:09copy-paste
- 21:09the whole thing
- 21:10or what will
- 21:11you do?
- 21:11It would take
- 21:12a lot of
- 21:13by-hand work.
- 21:14Yeah,
- 21:14it wouldn't be good.
- 21:15Yeah.
- 21:15Yeah,
- 21:16so that's really
- 21:16cool.
- 21:17And that was
- 21:18an interesting
- 21:18large scale,
- 21:19like,
- 21:20hey,
- 21:20we have to
- 21:20organize.
- 21:21We've got
- 21:21one month
- 21:22to do it.
- 21:22Let's make
- 21:23this happen.
- 21:23So on a
- 21:24much smaller
- 21:24scale,
- 21:25I recently
- 21:26decided to
- 21:27realize that
- 21:27some of my
- 21:28pages on my
- 21:29site were
- 21:29getting indexed
- 21:30by Google,
- 21:31not because
- 21:32anything on the
- 21:32internet was
- 21:33linking to them
- 21:33publicly,
- 21:34but something
- 21:35would be in
- 21:36Gmail or
- 21:36somebody would
- 21:37write it down
- 21:38and then Google
- 21:38would find it.
- 21:39So I just went
- 21:40through and put a
- 21:41bunch of no index
- 21:42meta tags on a
- 21:43bunch of my
- 21:43parts of my
- 21:44site.
- 21:44But it really
- 21:45scared me because
- 21:46I changed a
- 21:46whole bunch of
- 21:47it and I'm
- 21:47pretty sure I
- 21:48got it right.
- 21:48But what if I
- 21:50accidentally put
- 21:50no index on
- 21:51some of my
- 21:52course pages
- 21:53that advertise
- 21:54them and all
- 21:55of a sudden the
- 21:56traffic goes from
- 21:57whatever it is
- 21:57to literally
- 21:58zero because I
- 21:59accidentally told
- 22:00all the search
- 22:01engines,
- 22:01please don't tell
- 22:03anyone about
- 22:03this page.
- 22:04what I was
- 22:05doing actually
- 22:05right before we
- 22:06called unrelated
- 22:06to the fact that
- 22:07this was the
- 22:08topic was I
- 22:08was going to
- 22:09write a very
- 22:09simple web
- 22:10scrappy thing
- 22:11that goes and
- 22:11grabs my
- 22:12site map,
- 22:12hits every
- 22:13single page and
- 22:14just tells me
- 22:15the pages that
- 22:15are not indexed
- 22:16just for me to
- 22:17double check.
- 22:18But you know,
- 22:19that template
- 22:19didn't get reused
- 22:20somewhere where I
- 22:20didn't think it
- 22:21got reused,
- 22:22you know,
- 22:22like the little
- 22:22shared bit that
- 22:23has the head
- 22:24in it and so
- 22:25on.
- 22:25Yeah,
- 22:25it's sort of
- 22:26like in SEO,
- 22:27like search engine
- 22:28optimization,
- 22:28we have this
- 22:29thing,
- 22:30technical SEO.
- 22:31Yeah.
- 22:32And actually,
- 22:33it's another
- 22:33use case for
- 22:34web scraping or
- 22:35like crawling,
- 22:35where you want
- 22:38to crawl your
- 22:40own website,
- 22:40just as you
- 22:41know,
- 22:41you did and
- 22:42to learn the
- 22:43site map or
- 22:44to find pages
- 22:46where you don't
- 22:47have proper SEO
- 22:48optimization,
- 22:49like you don't
- 22:49have meta
- 22:50description on
- 22:51some pages,
- 22:51you have
- 22:53multiple like
- 22:54H1 tags or
- 22:55whatever.
- 22:56Right.
- 22:56and with
- 22:57crawling,
- 22:57you can figure
- 22:58these out.
- 22:59And I just
- 23:00remember the
- 23:01story from
- 23:01like 2016,
- 23:03where web
- 23:05scraping was
- 23:06used to
- 23:07reveal lobbying
- 23:09and corruption
- 23:10in Peru.
- 23:10Oh,
- 23:11wow.
- 23:11Okay.
- 23:12Yeah,
- 23:12I'm not 100%
- 23:13sure,
- 23:14but I think
- 23:14it was related
- 23:15to, you
- 23:16know,
- 23:16the Panama
- 23:16Papers.
- 23:17Yeah,
- 23:18I was going
- 23:19to guess it
- 23:19might have
- 23:20something to
- 23:20do with the
- 23:20Panama
- 23:21Papers,
- 23:21which was
- 23:22really interesting
- 23:22in and of
- 23:23itself.
- 23:23Yeah,
- 23:24yeah,
- 23:24and they
- 23:25actually,
- 23:25they use
- 23:26many tools
- 23:27to scrape
- 23:28the web,
- 23:28but they
- 23:29also use
- 23:30Scrappy to
- 23:30get like
- 23:31information from
- 23:32these,
- 23:33I guess,
- 23:33government
- 23:34websites or
- 23:35other websites.
- 23:36But yeah,
- 23:38like it's
- 23:38crazy that a
- 23:39web scraping
- 23:40can reveal
- 23:40these kinds
- 23:42of really,
- 23:42this is a
- 23:43big thing.
- 23:44Yeah.
- 23:44Corruption
- 23:45and web
- 23:46scraping can
- 23:46tell you
- 23:47that,
- 23:47hey,
- 23:48there is
- 23:48something wrong
- 23:49here,
- 23:49you should
- 23:50pay attention.
- 23:50It lets you
- 23:51automate the
- 23:52discovery and
- 23:53the linking
- 23:53of all this
- 23:54different data
- 23:54that was never
- 23:55intended to be
- 23:56put together,
- 23:57right?
- 23:57There's no
- 23:57API that's
- 23:58supposed to
- 23:58take like
- 23:59these donations,
- 24:00this investment,
- 24:02this other
- 24:03construction deal,
- 24:04or whatever the
- 24:05heck it was,
- 24:05and like link
- 24:06them together.
- 24:06But with
- 24:07web scraping,
- 24:07you can sort
- 24:08of pull it
- 24:09off,
- 24:09right?
- 24:09Yeah,
- 24:10you can
- 24:10structure the
- 24:11whole web.
- 24:11I mean,
- 24:12technically,
- 24:12you could
- 24:13structure the
- 24:14whole web,
- 24:14or you could
- 24:16get like a
- 24:17set of
- 24:17websites that
- 24:18are considered
- 24:19or that has
- 24:20the same kind
- 24:21of data you
- 24:22are looking
- 24:23for,
- 24:23like you
- 24:23can be
- 24:24e-commerce,
- 24:24fintech,
- 24:26real estate,
- 24:27whatever.
- 24:27You can grab
- 24:28those sites,
- 24:29extract the
- 24:30data,
- 24:30the publicly
- 24:31available data,
- 24:32structure it,
- 24:33and then you
- 24:34can do many
- 24:34sorts of
- 24:35things.
- 24:35You can do
- 24:35like NLP,
- 24:36you can just
- 24:37search in the
- 24:38data,
- 24:38you can do
- 24:39many different
- 24:39kinds of
- 24:40things.
- 24:41Yeah,
- 24:41that's cool.
- 24:42So let's talk
- 24:43a little bit
- 24:44specifically about
- 24:45Scrappy and
- 24:46maybe Scraping Hub
- 24:47as well,
- 24:48and some of the
- 24:48more general
- 24:49challenges you
- 24:50might run into
- 24:50with web scraping.
- 24:51So right on
- 24:52the Scrappy
- 24:53website,
- 24:53homepage,
- 24:54project site,
- 24:55there's a
- 24:56real simple
- 24:57example that
- 24:57says here's
- 24:58why you should
- 24:58use it.
- 24:58You can just
- 24:59create this
- 24:59class,
- 25:00it derives
- 25:00from Scrappy.
- 25:01spider,
- 25:01and you
- 25:02give it
- 25:02some URLs,
- 25:03and it
- 25:03has this
- 25:04parse
- 25:04function,
- 25:05and off
- 25:05it goes.
- 25:06Do you
- 25:06want to
- 25:06talk to us
- 25:07real quickly
- 25:07about what
- 25:08it's like
- 25:08to write
- 25:08code to do
- 25:09web scraping
- 25:10with this
- 25:11API?
- 25:11With Scrappy?
- 25:12Yeah.
- 25:12Yeah,
- 25:13so with
- 25:14Scrappy,
- 25:15if you use
- 25:16Scrappy,
- 25:16what you really
- 25:17get is like a
- 25:18full-fledged
- 25:19web crawling
- 25:20framework,
- 25:21or like a
- 25:22web scraping
- 25:22framework.
- 25:22So it really
- 25:24makes it easy
- 25:25for you to
- 25:26extract data
- 25:27from any
- 25:27website.
- 25:28And it
- 25:29has,
- 25:29there are other
- 25:30libraries like
- 25:31BeautifulSoup,
- 25:32or LXML,
- 25:33or in Java,
- 25:34we have JSUP,
- 25:35that are only
- 25:36focused around
- 25:37parsing HTML
- 25:38and getting,
- 25:39or getting data
- 25:40from HTML and
- 25:41XML files.
- 25:43Right,
- 25:43BeautifulSoup is
- 25:44I have the
- 25:44text,
- 25:45I have the
- 25:46HTML source,
- 25:47now tell me
- 25:47stuff about it,
- 25:48right?
- 25:48Right.
- 25:49That's sort of
- 25:50its whole job,
- 25:50yeah.
- 25:50Right,
- 25:51but Scrappy,
- 25:52I would say
- 25:53it's like maybe
- 25:5410% of the
- 25:55whole picture
- 25:55or the big
- 25:56picture,
- 25:57because with
- 25:57Scrappy,
- 25:58like,
- 25:59yeah,
- 25:59you can parse
- 25:59the HTML,
- 26:00but in
- 26:01real-world
- 26:02project,
- 26:03that's not the
- 26:04only task you
- 26:05need to do.
- 26:05In real-world
- 26:06project,
- 26:07you need to
- 26:08process the data
- 26:09as well.
- 26:10You need to
- 26:11structure the
- 26:12data properly,
- 26:13you need to
- 26:14maybe put it
- 26:15into a database,
- 26:16maybe export it
- 26:18as a CSV file
- 26:20or JSON,
- 26:20you need to
- 26:21clean the data,
- 26:22you need to
- 26:23normalize the
- 26:23data.
- 26:24In real-world
- 26:25scenarios,
- 26:25you need to
- 26:26do a lot of
- 26:26things,
- 26:27not just
- 26:27scraping the
- 26:28data,
- 26:28and Scrappy
- 26:29really makes
- 26:30it easy to
- 26:31develop these
- 26:32spiders that
- 26:34grab the
- 26:34data,
- 26:35and then
- 26:36right there in
- 26:37Scrappy,
- 26:37you can clean
- 26:38it,
- 26:39you can process
- 26:40it,
- 26:40and when the
- 26:41data leaves
- 26:42Scrappy,
- 26:43it's usable
- 26:44for whatever
- 26:45you want to
- 26:46use it for.
- 26:46Right,
- 26:46maybe you get
- 26:47a list or
- 26:48sequence of
- 26:49dictionaries that
- 26:50have the pieces
- 26:51of data that
- 26:52you went after
- 26:53or something like
- 26:53that.
- 26:53Yeah,
- 26:54right.
- 26:54So that's why
- 26:56I really like
- 26:56Scrappy,
- 26:57but also I think
- 26:59it's the best
- 26:59framework to
- 27:00maintain your
- 27:01spiders,
- 27:01because a big
- 27:03problem in
- 27:03web scraping
- 27:04is that once
- 27:05you write the
- 27:06spider,
- 27:07it works,
- 27:08you get the
- 27:08data,
- 27:09it will
- 27:09probably not
- 27:10work in
- 27:11the six
- 27:12months in
- 27:12the future
- 27:12because the
- 27:13website changes
- 27:14or layout
- 27:16changes.
- 27:16They've decided
- 27:17to switch
- 27:18JavaScript
- 27:19front-end
- 27:19frameworks or
- 27:20redesign the
- 27:21navigation or
- 27:22something,
- 27:22right?
- 27:23Exactly.
- 27:23And so you
- 27:24need to adjust
- 27:25your code,
- 27:26adjust your
- 27:27selectors,
- 27:28you need to
- 27:29maybe adjust
- 27:30the whole
- 27:30processing
- 27:31part of
- 27:32Scrappy,
- 27:33because maybe
- 27:34in the past
- 27:35you were able
- 27:36to extract
- 27:37only messy
- 27:38code from
- 27:39the HTML,
- 27:39but they did
- 27:40some changes
- 27:41on the website.
- 27:42Now it's
- 27:42clean,
- 27:43you don't need
- 27:43so much
- 27:44processing.
- 27:44And with
- 27:46Scrappy,
- 27:46it's really
- 27:47easy to
- 27:48maintain the
- 27:48code,
- 27:48which is,
- 27:49you know,
- 27:49it's really
- 27:50important if
- 27:50you rely on
- 27:51web-extracted
- 27:52data on a
- 27:53daily basis,
- 27:53you need to
- 27:54maintain the
- 27:55code.
- 27:55Yeah,
- 27:55really neat.
- 27:56So to me,
- 27:57when I look
- 27:58at this simple
- 27:58API here,
- 27:59it's like you
- 28:00create a class,
- 28:01you give it a
- 28:02set of start
- 28:02URLs,
- 28:03and there's a
- 28:04parse function,
- 28:04and that
- 28:05comes in,
- 28:05you run some
- 28:06CSS selectors on
- 28:07what you get.
- 28:08For each thing
- 28:09that you find,
- 28:09you can yield
- 28:10that back as
- 28:11part of the
- 28:11thing, like the
- 28:12result you found,
- 28:13and then you
- 28:14can follow the
- 28:15next one.
- 28:15I think that's
- 28:16probably the
- 28:16biggest differentiator
- 28:17from what I can
- 28:18tell is,
- 28:19it's like as
- 28:20you're parsing
- 28:21it, you're
- 28:21directing it to
- 28:22go do more
- 28:23discovery, maybe
- 28:25on linked pages
- 28:26and things like
- 28:26that.
- 28:27Yeah, like on
- 28:28websites where
- 28:29you need to go
- 28:30deeper, maybe
- 28:31because, you
- 28:33know, you need to
- 28:33go deeper in the
- 28:34sitemap or you
- 28:36need to like
- 28:36paginate, you
- 28:37need to do more
- 28:39requests to get
- 28:40the data.
- 28:41Yeah.
- 28:41In tools like
- 28:43BeautifulSoup, you
- 28:43would need to
- 28:45sort of create your
- 28:46own logic or like,
- 28:47you know, how you
- 28:48want to do that.
- 28:49But in Scrappy, it's
- 28:50already sort of
- 28:51straightforward how
- 28:53you want to do
- 28:53that or how you
- 28:54can do that.
- 28:55And you just need
- 28:56to just click this
- 28:57button, click this
- 28:58button, and you
- 28:58paginate with
- 29:00Scrappy because you
- 29:01have this high-level
- 29:02functions and
- 29:04methods that let
- 29:05you paginate and
- 29:06let you do things
- 29:07in a chain, you
- 29:08know?
- 29:08Yeah.
- 29:09Yeah, very cool
- 29:10API.
- 29:10So let's talk about
- 29:11some of the
- 29:12challenges you might
- 29:13get.
- 29:14I mean, probably to
- 29:15me, the biggest
- 29:15challenge, well,
- 29:16there's two problems
- 29:17that I would say, the
- 29:18two biggest
- 29:19challenges.
- 29:19One is probably
- 29:21maybe generally you
- 29:23could call it data
- 29:24quality, but more
- 29:25specifically like the
- 29:26structure changed,
- 29:27right?
- 29:28they've added a
- 29:28column to this
- 29:29table and it's not
- 29:30what I thought it
- 29:31was anymore.
- 29:32Like it used to be
- 29:33temperature and now
- 29:34it's pressure because
- 29:35they've added that
- 29:36column and I wrote it
- 29:37to have three columns
- 29:38in the table, now it's
- 29:38got four.
- 29:39The other one is I go
- 29:41and I get the source
- 29:42code of the page and
- 29:43it says, you know,
- 29:45view.application or
- 29:46there's like an
- 29:48Angular app or
- 29:49something and you get
- 29:50just a bunch of
- 29:51script tags that
- 29:52have no data in
- 29:53them because it's not
- 29:54actually executed yet.
- 29:55Yeah, I mean, this
- 29:57is like really all
- 29:58the things that all
- 29:59the reasons why you
- 30:00need to maintain the
- 30:01code, which can be,
- 30:02you know, it takes
- 30:03time to maintain the
- 30:05code.
- 30:05Actually, that's why
- 30:06there are more
- 30:08advancing machine
- 30:10learning technologies
- 30:11that pretty much
- 30:12maintain the code
- 30:14for you.
- 30:15Oh, wow.
- 30:15Okay.
- 30:15Give us an example
- 30:16of that.
- 30:17Like find me the
- 30:18title or find me the
- 30:19stock price off of
- 30:20this page, machine
- 30:21magic.
- 30:21Yeah.
- 30:22So actually it's
- 30:23not that big of a
- 30:24magic.
- 30:24Like in the future,
- 30:26you won't need to
- 30:27write things like
- 30:28selectors.
- 30:29You don't need to
- 30:30tell Scrappy or
- 30:32like, you know,
- 30:32whatever tool you
- 30:33use to, hey, this
- 30:35is the price title,
- 30:37whatever.
- 30:38I want to extract
- 30:39it.
- 30:39This is the selector
- 30:41where you can find it
- 30:42in the HTML.
- 30:43In the future, you
- 30:44will not need to do
- 30:45that.
- 30:46In the future, what
- 30:47you will only need to
- 30:49say is that this is
- 30:50the page.
- 30:51this is real estate
- 30:52listing or this is a
- 30:54product page or this
- 30:56is some kind of
- 30:57financial page.
- 30:59So you just need to
- 31:00say the data type.
- 31:01Yeah.
- 31:02And then the machine
- 31:04will know what
- 31:06fields to look for.
- 31:07So it will know that
- 31:09if it's a product page,
- 31:10you probably need
- 31:12like price.
- 31:13You probably need
- 31:13product title or
- 31:15like product name,
- 31:16sorry, description,
- 31:17stock information,
- 31:19maybe reviews, if
- 31:20any.
- 31:20So in the future,
- 31:21you just need to
- 31:22specify the data type
- 31:24and you will get all
- 31:25the data fields that
- 31:26you want with ML.
- 31:28Yeah.
- 31:28That's like a dream.
- 31:29Well, it's sort of
- 31:31like it's a reality in
- 31:32some cases because
- 31:33like, you know, there
- 31:34are many, there are
- 31:35some products out
- 31:36there that do this
- 31:38at Scraping Hub.
- 31:39We have like, for
- 31:40example, news API,
- 31:41which does exactly
- 31:43this thing for
- 31:44articles and news.
- 31:45Okay.
- 31:46Yeah.
- 31:46So what you do is
- 31:47that, hey, this is
- 31:48the page URL.
- 31:50give me everything
- 31:50and you get the
- 31:52article title, you
- 31:53get the text body,
- 31:55you get, you know,
- 31:56everything that is on
- 31:57the page.
- 31:58Well, and if any
- 31:59place is going to
- 32:00have enough data on
- 32:01scraping to like
- 32:02answer those kinds of
- 32:03questions more
- 32:04generally, it sounds
- 32:05like you guys might.
- 32:06You guys do so much
- 32:07web scraping, right?
- 32:08That like way more
- 32:09than a lot of people
- 32:10in terms of as a
- 32:12platform.
- 32:12I don't know how
- 32:13you like share that
- 32:14across projects.
- 32:15I don't think that,
- 32:16I don't see a good
- 32:17way to do that, but
- 32:17it seems like you
- 32:18should be in a
- 32:19position that somehow
- 32:20you could build some
- 32:21cool tools around all
- 32:22that.
- 32:22Yeah, we do a lot of
- 32:24web scraping, as you
- 32:25said.
- 32:25And it's really about
- 32:27the biggest problem is
- 32:28that there is no one
- 32:30schema that websites
- 32:32follow when it comes
- 32:33to data.
- 32:34So when you scrape,
- 32:36you need to like
- 32:37figure out a structure
- 32:38that would work for
- 32:40all the websites.
- 32:41and then you extract,
- 32:43you sort of like
- 32:44standardize the data.
- 32:45And that's why the
- 32:46data type is important
- 32:47to specify.
- 32:48Right.
- 32:49What about JavaScript?
- 32:50That's all the cool
- 32:52kids say they should,
- 32:53you don't write server
- 32:54code anymore.
- 32:55You don't write
- 32:56templates.
- 32:56Just you write just
- 32:58APIs and you talk to
- 32:59them with HTML and
- 33:00JavaScript.
- 33:00But that doesn't
- 33:01scrape very well.
- 33:02I'm not sure that's
- 33:02necessarily what you
- 33:03should be doing,
- 33:03but entirely, but a
- 33:05lot of people are and
- 33:06it makes web scraping
- 33:07definitely more
- 33:08challenging.
- 33:09Yeah.
- 33:09Like nowadays,
- 33:10all the websites
- 33:11have some kind of
- 33:12JavaScript running.
- 33:13And if the data you
- 33:16need to extract is
- 33:17rendered with
- 33:18JavaScript, that can
- 33:19be a challenge.
- 33:21And first, if you're
- 33:22writing a spider,
- 33:23first, you should
- 33:25look for ways to get
- 33:26the data without
- 33:27executing JavaScript.
- 33:28You can do this
- 33:30sort of, you know,
- 33:31I call them hidden
- 33:32APIs when there is
- 33:34no documented API
- 33:35for the website.
- 33:36But if you look in
- 33:38the background,
- 33:39background, that is
- 33:40actually a public
- 33:41API available.
- 33:42Right.
- 33:42So it's clearly going
- 33:43back, like if you've
- 33:44got a Vue.js front
- 33:46end, it's probably
- 33:47calling some function
- 33:48that's returning like a
- 33:50JSON result of the
- 33:52data you actually
- 33:52want.
- 33:53You just got to look
- 33:54in your web browser
- 33:54tools to see that
- 33:55happening, right?
- 33:56Yeah, exactly.
- 33:57Like with AJAX calls,
- 33:59many times that's the
- 34:00case that you just
- 34:02need to sort of grab
- 34:02the JSON and you can
- 34:04get the data easily.
- 34:05Well, and it's
- 34:06formatted JSON, right?
- 34:07It's not just HTML.
- 34:08I mean, it's like
- 34:09pretty sweet actually
- 34:10to get a hold of
- 34:11that feed.
- 34:11Oh, yeah.
- 34:12But on the other
- 34:13side, if you cannot
- 34:14find an API like
- 34:15this, you need to
- 34:16execute JavaScript using
- 34:18some kind of headless
- 34:20browser like Selenium
- 34:21or Puppeteer or
- 34:23Splash.
- 34:23And because, you know,
- 34:25you need an actual
- 34:25browser to execute
- 34:26JavaScript.
- 34:27Right.
- 34:27But then it's
- 34:29going to take more
- 34:30hardware resources to
- 34:32run JavaScript.
- 34:32So it's going to be
- 34:33slower and it's going
- 34:35to make the whole
- 34:36process a little bit
- 34:37more complicated.
- 34:38Yeah.
- 34:38There's probably no
- 34:40mechanism built right
- 34:41into Scrapey that
- 34:42will render the
- 34:43JavaScript, is there?
- 34:44Like Scrappy itself
- 34:46cannot render JavaScript,
- 34:47but there is a really
- 34:49neat integration with
- 34:50Splash.
- 34:50Okay.
- 34:51Splash is also
- 34:53made, you know, it was
- 34:53created by Scraping Hub,
- 34:55so it's really easy to,
- 34:56and Splash is sort of
- 34:58like a headless browser
- 34:59created only for web
- 35:00scraping.
- 35:01and you can integrate
- 35:02Splash with Scrappy
- 35:04really easily.
- 35:05It's literally just like
- 35:07a middleware in Scrappy.
- 35:08And then it will
- 35:09execute JavaScript for
- 35:10you.
- 35:11Yeah.
- 35:11Sweet.
- 35:11Yeah.
- 35:12You will be able to
- 35:13see the data and then
- 35:14you will be able to
- 35:15extract it.
- 35:16Right.
- 35:16It says the headless
- 35:18browser designed
- 35:19specifically for web
- 35:20scraping.
- 35:20Turn any JavaScript
- 35:21heavy site into data.
- 35:23Right.
- 35:23Cool.
- 35:24I'll put a link to
- 35:25that.
- 35:25That's pretty neat.
- 35:26And that's open
- 35:26source.
- 35:27People can just use
- 35:28that as well or
- 35:28what's the story with
- 35:29that?
- 35:30Yeah.
- 35:30Just like Scrappy,
- 35:31they can set up
- 35:32their own server
- 35:33and you can use it
- 35:34that way or you can
- 35:36also host it on
- 35:37Scraping Hub.
- 35:37Talk Python To Me
- 35:41is partially supported
- 35:42by our training
- 35:42courses.
- 35:43How does your team
- 35:44keep their Python
- 35:45skills sharp?
- 35:46How do you make
- 35:47sure new hires get
- 35:48started fast and
- 35:49learn the Pythonic
- 35:49way?
- 35:50If the answer is a
- 35:52series of boring
- 35:52videos that don't
- 35:53inspire or a
- 35:55subscription service
- 35:56you pay way too
- 35:56much for and use
- 35:57way too little,
- 35:58listen up.
- 35:59At Talk Python
- 36:00Training, we have
- 36:01enterprise tiers for
- 36:02all of our courses.
- 36:03Get just the one
- 36:04course you need for
- 36:05your team with full
- 36:06reporting and
- 36:07monitoring.
- 36:07Or ditch that
- 36:09unused subscription
- 36:09for our course
- 36:10bundles which
- 36:11include all the
- 36:12courses and you
- 36:12pay about the same
- 36:13price as a
- 36:13subscription once.
- 36:15For details,
- 36:16visit training.talkpython.fm
- 36:18slash business or
- 36:20just email sales at
- 36:21talkpython.fm.
- 36:24Yeah, so let's
- 36:25maybe round out
- 36:26our conversation
- 36:27talking about
- 36:27hosting.
- 36:28So I can go and
- 36:30run web scraping on
- 36:31my system and that
- 36:33sometimes works pretty
- 36:35well, sometimes it
- 36:35doesn't.
- 36:36There was this time
- 36:37a friend of mine was
- 36:38thinking about getting
- 36:39a car and putting it
- 36:40on one of these car
- 36:40sharing sites, keep it
- 36:42a little bit general
- 36:42and we wanted to
- 36:44know like, okay, for
- 36:45a car that's similar to
- 36:46the kind of car he's
- 36:47thinking about getting,
- 36:47how often is it
- 36:48rented?
- 36:49What does it rent
- 36:50for?
- 36:50Like, so would it
- 36:51be worthwhile as
- 36:53just a pure investment,
- 36:54right?
- 36:54So I wrote up some
- 36:55web scraping stuff
- 36:56that would just
- 36:57monitor like a couple
- 36:58of cars I picked.
- 36:59After a little while,
- 37:00they didn't talk to
- 37:01me anymore.
- 37:02The website was
- 37:03mad at me for like
- 37:04always asking about
- 37:05this car.
- 37:06Yeah.
- 37:07So that seems like
- 37:08a common problem and
- 37:09if I do that for my
- 37:10house, I probably
- 37:11can't check out that
- 37:12site anymore for a
- 37:13while, right?
- 37:14I probably shouldn't
- 37:14do it for my house,
- 37:15but even from a
- 37:16dedicated server, like
- 37:17that might cause
- 37:18problems.
- 37:18Yeah, it's not just
- 37:20with web scraping.
- 37:20Like I remember I
- 37:22was doing some kind
- 37:22of financial research.
- 37:24It was about like one
- 37:25of the cryptocurrencies
- 37:26and I was using an
- 37:28actual API.
- 37:28Like I wasn't
- 37:29scraping.
- 37:29I was using an
- 37:30actual API and it
- 37:31was pretty basic.
- 37:32Like I was just
- 37:33learning how to use
- 37:34this thing and I
- 37:36created a for loop
- 37:37and I put the
- 37:39request, the API
- 37:40request in the
- 37:41for loop and I was
- 37:43just testing and by
- 37:45accident, I put like
- 37:46a huge number in
- 37:49the for loop, like
- 37:50I don't know, like
- 37:50a million or
- 37:51something.
- 37:51And it created a
- 37:53million requests.
- 37:54I mean, it tried to
- 37:56create a million
- 37:56requests, but it
- 37:57stopped after like,
- 37:58I don't know, maybe
- 37:58like 10,000 requests
- 38:00in a minute.
- 38:01Right.
- 38:02And because, you
- 38:03know, the server
- 38:03didn't like that I
- 38:04was doing that.
- 38:04And it's the same
- 38:06thing with web
- 38:06scraping.
- 38:07You need to be
- 38:08really careful not
- 38:09to hit the website
- 38:10too hard because
- 38:11when you scrape the
- 38:13web, it's really
- 38:14important.
- 38:14I mean, it's very
- 38:15important to be
- 38:17ethical and be
- 38:18legal.
- 38:19And one of the
- 38:20things that you can
- 38:21do to achieve
- 38:21these is to just
- 38:23put some kind of
- 38:24delay limit just
- 38:26over a respect the
- 38:27website and make
- 38:27sure that you don't
- 38:28cause any harm to
- 38:30the website.
- 38:30Right.
- 38:31As soon as people
- 38:32think that what
- 38:33you're doing, you
- 38:34think you're just
- 38:34getting data, but
- 38:35they might perceive
- 38:36it as this is the
- 38:37distributed denial
- 38:38of service attack
- 38:39against my site.
- 38:40We're going to
- 38:40block this person,
- 38:41right?
- 38:42That's not a good
- 38:42situation you want to
- 38:44be in.
- 38:44And it's also not
- 38:45super nice to
- 38:45whoever runs that
- 38:46website to hammer
- 38:47it.
- 38:48Exactly.
- 38:48The website doesn't
- 38:49know what you want
- 38:51to do.
- 38:51It just sees a bot
- 38:52and it's really
- 38:53like, you know,
- 38:54because web scraping
- 38:55itself is legal.
- 38:56You can do it if it's
- 38:58a publicly available
- 38:58website and you
- 39:00need to make sure
- 39:01that you are being,
- 39:03I mean, we use this
- 39:03in the web scraping
- 39:04community.
- 39:05You need to be nice.
- 39:06You need to be nice
- 39:08to the websites and
- 39:09you know, you can
- 39:09look at the robots
- 39:10text file.
- 39:11Usually there is a,
- 39:12like a,
- 39:13a delay specified
- 39:15in the robots
- 39:15text file that
- 39:16tells you that,
- 39:17hey, you should
- 39:18put like three
- 39:19seconds between
- 39:20each request.
- 39:21And, but just
- 39:23in general, even
- 39:23if there is no
- 39:24such a rule defined
- 39:25in the robots
- 39:26text file, you
- 39:27should pay
- 39:28attention.
- 39:28You should be
- 39:29careful with your,
- 39:30how many requests
- 39:31you make, how
- 39:32frequently you make
- 39:33those requests.
- 39:34So yeah, it's
- 39:35important.
- 39:35Yeah.
- 39:36Interesting.
- 39:36And so I guess
- 39:38one option is you
- 39:40guys have a cool
- 39:41thing, which I just
- 39:42discovered.
- 39:42I don't know how
- 39:43new it is, but
- 39:44scrappy D, a daemon
- 39:45that lets you
- 39:46basically deploy your
- 39:48scrappy scripts to
- 39:50it and it'll schedule
- 39:51and run them and
- 39:52that's pretty cool and
- 39:53you can control that.
- 39:53So you could set that
- 39:54up yourself or
- 39:55obviously you have the
- 39:57business side of your
- 39:58whole story, which is
- 39:59scraping hub.
- 40:00So what does
- 40:01scraping hub do that
- 40:02makes this better?
- 40:03Yes.
- 40:04Then just like getting
- 40:05a server at AWS or
- 40:07Linode or something
- 40:08like that.
- 40:08Yeah.
- 40:09So scraping hub is
- 40:11really about, you can
- 40:12deploy your spiders, but
- 40:14it's really, it's made
- 40:15for web scraping and
- 40:16there is all the tools
- 40:18available in the
- 40:19scraping hub platform
- 40:20that you would want to
- 40:22use for web scraping.
- 40:23Like, you know, we
- 40:24mentioned scrappy and
- 40:25splash in the
- 40:26scraping hub platform.
- 40:27You can upload your
- 40:28spider, your scrappy
- 40:29spider, and then you
- 40:30can, with a click of
- 40:31a button, you can add
- 40:32splash.
- 40:33So it renders
- 40:34JavaScript or you can
- 40:36also, if you want to
- 40:38use proxies for web
- 40:39scraping, you can, with
- 40:40a click of a button, you
- 40:41can add proxies to your
- 40:43web scraping.
- 40:44You can also, if you
- 40:45have a website, like we
- 40:47mentioned, you know,
- 40:48articles and news, if you
- 40:49want to extract data, we
- 40:51have an API, so you
- 40:52don't have to actually
- 40:53write the spider.
- 40:54You can just use the
- 40:56API and get the data so
- 40:58you don't need to
- 40:58maintain the code.
- 40:59So it's scraping
- 41:00up is really just the, I
- 41:02work at scraping
- 41:02up, but I truly
- 41:03believe that it's the
- 41:04best platform if you're
- 41:05doing web scraping at
- 41:07scale, because you have
- 41:08all the tools in one
- 41:10place that you would
- 41:11want to use for web
- 41:12scraping.
- 41:12Right, right.
- 41:14So a lot of the stuff
- 41:15you might bring your own
- 41:17infrastructure for, you
- 41:18guys have like as a
- 41:19service type stuff?
- 41:20Yeah, exactly.
- 41:21You can sign up.
- 41:22We have a free trial for,
- 41:24I think, for most of our
- 41:25services.
- 41:26You can try it.
- 41:27You can see how it
- 41:28works.
- 41:28And then there's a
- 41:29monthly fee and that's
- 41:31it.
- 41:31Okay.
- 41:31Yeah, that seems pretty
- 41:32awesome.
- 41:33And also we have a lot
- 41:34of clients who don't want
- 41:35to deal with the stuff,
- 41:36deal with the technical
- 41:37details.
- 41:38So they just say that,
- 41:39hey, I want this type of
- 41:40data from these websites,
- 41:41give me the data.
- 41:42And so we just do the
- 41:44hardware for them.
- 41:45Right.
- 41:45Maybe they're not even
- 41:46Python people.
- 41:47Yeah.
- 41:47They might be like, they
- 41:49don't even know how to
- 41:49code or like.
- 41:50Right.
- 41:51They could be political
- 41:52scientists.
- 41:52They're like, we need to
- 41:53just scrape this.
- 41:54But like you guys do
- 41:55scraping, right?
- 41:56Yeah.
- 41:56Yeah, exactly.
- 41:57So let's round out our
- 41:59conversation on this.
- 42:00Just a quick comment on
- 42:02Scraping Hub or a quick
- 42:03thought on it.
- 42:04So when I talked to Pablo
- 42:05back in 2016, so I had a
- 42:08show with him about
- 42:09Scraping and Scraping Hub
- 42:11and all that back in
- 42:12episode 50, four years ago
- 42:14or something.
- 42:14One of the things that
- 42:16really impressed me about
- 42:17what you guys are doing
- 42:18and continues to be the
- 42:19case is you've taken
- 42:21pretty straightforward
- 42:22open source projects,
- 42:24not something completely
- 42:26insane, like a whole new
- 42:27database model or
- 42:28something, but just pretty
- 42:29straightforward, but
- 42:30polished model of web
- 42:32scraping.
- 42:32And you built a really
- 42:33powerful business on top
- 42:35of it.
- 42:35And I think it's an
- 42:36interesting model for
- 42:38taking open source and
- 42:39making it your job more
- 42:40than just I'll do
- 42:42consulting in this thing,
- 42:43right?
- 42:43If I wrote this web
- 42:44framework, I could maybe
- 42:45sustain myself by
- 42:47consulting with people who
- 42:48want to write websites in
- 42:49that framework or so.
- 42:50But this is a pretty
- 42:51interesting next level
- 42:53type of thing that you
- 42:54guys pulled off here.
- 42:55And what are your
- 42:56thoughts on this?
- 42:56Yeah, 100% agree.
- 42:58Like I think, you know,
- 42:59Pablo and Pablo Hoffman
- 43:01and Shane Evans, they did
- 43:02an awesome job when they
- 43:04created Scrappy.
- 43:05Like at the time, it was
- 43:06the first real web
- 43:08scraping framework, as I
- 43:09know.
- 43:10And they open sourced it.
- 43:11And it's really like if
- 43:13you look at the GitHub
- 43:14page of Scrappy, it's
- 43:16really like I feel like
- 43:17it's a community.
- 43:18Like people are chatting
- 43:20about this.
- 43:20People are talking about
- 43:22how the community can
- 43:23improve this tool.
- 43:25And then the fact...
- 43:26You've got like 17,000
- 43:28GitHub questions or
- 43:29something like that.
- 43:30Oh, yeah.
- 43:30Tagged on it.
- 43:31Yeah, it's quite a bit.
- 43:31Yeah.
- 43:32And the fact that Pablo
- 43:34and Shane were able to
- 43:35pull this thing into
- 43:36business, but in a
- 43:37really...
- 43:38Like people can still
- 43:39use Scrappy without
- 43:40using our services.
- 43:42They can still use
- 43:43Splash without paying.
- 43:45They can use it.
- 43:45It's open source.
- 43:47So the fact that they
- 43:48built on top of the
- 43:50open source tools in a
- 43:51way that you don't need
- 43:53to be affiliated with the
- 43:54company to get the
- 43:56benefits of Scrappy and
- 43:57other open source tools.
- 43:58Like there are many
- 43:59other tools.
- 44:00It's not just Scrappy.
- 44:01Like there are so many
- 44:02other tools for web
- 44:03scraping.
- 44:04And I agree.
- 44:05I think it's just really
- 44:06amazing that they have
- 44:08been doing this.
- 44:09Yeah.
- 44:09It seems like it's
- 44:10really adding value
- 44:11because if not the core
- 44:13thing is already open
- 44:14source and people would
- 44:15just use it, you know?
- 44:16Yeah.
- 44:16Like especially if they
- 44:18want to do it at scale.
- 44:19Yeah.
- 44:20You just cannot do huge
- 44:22things like millions of
- 44:23extracted records or
- 44:24things like that on your
- 44:26computer or on your
- 44:27laptop.
- 44:28You just cannot do that.
- 44:29No, you get about 50,000
- 44:31and then you get blocked.
- 44:32Yeah.
- 44:33Yeah.
- 44:33That's an option as well.
- 44:34Yeah, exactly.
- 44:36So yeah, very cool.
- 44:37I think it's a really neat
- 44:38example because a lot of
- 44:39people are thinking about
- 44:40how do I take this thing
- 44:41that's got some traction
- 44:42I'm doing with open source
- 44:43and make this my job
- 44:45because I'm tired of
- 44:46filling Jira tickets at
- 44:48this thing that's kind of
- 44:49okay but not really my
- 44:50passion, right?
- 44:51And cool example.
- 44:52So congrats to you guys.
- 44:53Keep up the good work.
- 44:54Yeah, we are.
- 44:55We definitely try our best.
- 44:57There are some awesome
- 44:58things to come in the
- 45:00web scraping world,
- 45:01I believe, with the
- 45:02advancements of machine
- 45:03learning and other stuff.
- 45:04So it's going to be really
- 45:06interesting to see what's
- 45:07going to happen in the
- 45:08next few years.
- 45:09Yeah, for sure.
- 45:10All right.
- 45:10Well, I think that's probably
- 45:11it for the time we got to
- 45:12talk about web scraping.
- 45:13But the final two questions
- 45:15before you get out of here,
- 45:16you're going to write some
- 45:17code.
- 45:17What editor do you use?
- 45:18Python code?
- 45:19PyCharm.
- 45:20PyCharm.
- 45:21Right on.
- 45:21And then notable PyPI
- 45:23package.
- 45:23I mean, there's obviously
- 45:25pip install, scrappy, but
- 45:26maybe some project that you
- 45:28came across, you know, like,
- 45:29oh, this is so awesome.
- 45:30People should know about
- 45:31X.
- 45:32Oh, actually, it's a hard
- 45:33question because I've been
- 45:35sort of out of the game for
- 45:37a lot of months now.
- 45:38Aside from scrappy, I just
- 45:41really like to, I don't have
- 45:43one specific example.
- 45:43I just really like to find
- 45:46these GitHub repositories
- 45:47where, when it's not like
- 45:49a library, but it's like a
- 45:50collection of, like, there
- 45:52are many libraries, GitHub
- 45:54repos with a collection of
- 45:55templates.
- 45:56Right.
- 45:56You know, like, hey, if
- 45:58you're a beginner, you can
- 45:59use these templates to get
- 46:00started.
- 46:01And for me, that was
- 46:02really useful when I started
- 46:04out with using a new tool
- 46:05like scrappy or other
- 46:06libraries is that you can
- 46:09use these starter codes
- 46:11sort of.
- 46:12Right, right.
- 46:12I wonder if there's a
- 46:13better scrappy, possibly.
- 46:15Probably.
- 46:15Yeah.
- 46:16Yeah.
- 46:16There is.
- 46:17I'll throw it into the
- 46:19show notes, but yeah.
- 46:21Cool.
- 46:21But just cookie cutter, make
- 46:23me a scrappy project.
- 46:24Let's roll and do some
- 46:25web scraping.
- 46:26Pretty neat.
- 46:26Also, there is a, you
- 46:27know, just last note,
- 46:28awesome.
- 46:28I think it's got awesome
- 46:30web scraping.
- 46:31OK.
- 46:31Or something like that,
- 46:33which has hundreds of
- 46:34tools for web scraping.
- 46:35Oh, yeah.
- 46:36We can link it later.
- 46:38Maybe if I find it.
- 46:39OK.
- 46:39Yeah.
- 46:40It's got awesome web
- 46:41scraping on GitHub.
- 46:42Yeah.
- 46:43Nice.
- 46:43I'll put that in the show
- 46:44notes as well.
- 46:45I love those awesome lists.
- 46:46Yeah.
- 46:46It's easy to get lost
- 46:48because you were like, oh,
- 46:49I have this one thing and I
- 46:50use it.
- 46:50Then all of a sudden you're
- 46:51like, oh, look at that.
- 46:52There's like 10 other
- 46:54options in this thing that I
- 46:55thought I knew.
- 46:55Yeah, exactly.
- 46:57Awesome.
- 46:58All right.
- 46:58Attila, it's been great to
- 47:00chat with all these, share
- 47:01all these web scraping
- 47:02stories and chat with you.
- 47:03So thanks for being here.
- 47:04Yeah, it's been amazing.
- 47:05Thank you.
- 47:05Thank you very much.
- 47:06Yeah, you bet.
- 47:07Bye-bye.
- 47:07Bye.
- 47:08This has been another episode
- 47:10of Talk Python To Me.
- 47:11Our guest in this episode has
- 47:13been Attila Toth and it's
- 47:14been brought to you by Talk
- 47:15Python Training and Linode.
- 47:17Start your next Python project
- 47:19on Linode's state-of-the-art
- 47:21cloud service.
- 47:21Just visit talkpython.fm
- 47:23slash Linode, L-I-N-O-D-E.
- 47:26You'll automatically get a
- 47:27$20 credit when you create a
- 47:29new account.
- 47:29Want to level up your Python?
- 47:31If you're just getting
- 47:32started, try my Python
- 47:34Jumpstart by Building
- 47:3510 Apps course.
- 47:36Or if you're looking for
- 47:37something more advanced,
- 47:38check out our new Async course
- 47:40that digs into all the
- 47:42different types of Async
- 47:43programming you can do in
- 47:44Python.
- 47:44And of course, if you're
- 47:45interested in more than
- 47:46one of these, be sure to
- 47:48check out our Everything
- 47:49Bundle.
- 47:49It's like a subscription
- 47:50that never expires.
- 47:51Be sure to subscribe to the
- 47:53show.
- 47:53Open your favorite podcatcher
- 47:54and search for Python.
- 47:55We should be right at the
- 47:56top.
- 47:57You can also find the
- 47:58iTunes feed at /itunes,
- 47:59the Google Play feed at
- 48:01slash Play, and the
- 48:02direct RSS feed at
- 48:03/rss on
- 48:05talkpython.fm.
- 48:06This is your host,
- 48:07Michael Kennedy.
- 48:08Thanks so much for
- 48:09listening.
- 48:09I really appreciate it.
- 48:10Now get out there and
- 48:11write some Python code.
- 48:12you're welcome.
- 48:13Bye.
- 48:13Thank you.