Latest / CyberCode Academy / Course 40 - Web Scraping with Python | Episode 29: From Feed and Sitemap Spiders to CrawlSpider Demos
Transcript
- 0:00Speaker 1: I want you to imagine something for a second. Imagine
- 0:02Speaker 1: having an army of assistance like tireless, perfectly obedient assistants
- 0:08Speaker 1: who work twenty four hours a day, seven days a
- 0:10Speaker 1: week without ever complaining. That would be nice, right, And
- 0:14Speaker 1: their only job, their entire purpose, is traveling across the vast,
- 0:19Speaker 1: chaotic landscape of the Internet, gathering exactly the specific information
- 0:23Speaker 1: you need, organizing it flawlessly, and just you know, handing
- 0:27Speaker 1: it back to you on a silver platter.
- 0:29Speaker 2: It definitely sounds like some kind of sci fi concept,
- 0:31Speaker 2: but honestly, that is the literal reality of webscraping.
- 0:34Speaker 1: Yeah.
- 0:35Speaker 2: When you understand how to build and command these automated
- 0:38Speaker 2: digital assistants what developers actually call web spiders, you effectively
- 0:42Speaker 2: turn the entire Internet into your own personal, queriable database.
- 0:46Speaker 1: Welcome to this deep dive today. We are looking at
- 0:48Speaker 1: a massive stack of notes, documentation, and architecture diagrams focused
- 0:53Speaker 1: entirely on the scrapy framework. It's a huge topic, it is,
- 0:56Speaker 1: and our mission is to synthesize all of this material
- 0:59Speaker 1: for you to break down and exactly how you build,
- 1:01Speaker 1: deploy and control these webspids.
- 1:03Speaker 2: Yeah, from the ground up, exactly.
- 1:04Speaker 1: We're going fundamentally into the logic, starting with spiders that
- 1:08Speaker 1: handle highly organized data feeds, and working our way all
- 1:11Speaker 1: the way up to engineering custom free roaming bots capable
- 1:14Speaker 1: of navigating complex websites entirely on their own.
- 1:17Speaker 2: And I just want to say, it's an incredibly empowering
- 1:19Speaker 2: skill set. If you are, say, building a custom data
- 1:23Speaker 2: set to train a machine learning model, or tracking competitor inventory,
- 1:28Speaker 2: or just doing large scale market research, understanding the mechanics
- 1:32Speaker 2: of these spiders is completely non negotiable.
- 1:35Speaker 1: Okay, let's unpack this. So again, to send a spider
- 1:37Speaker 1: out into the wild to gather data, jumping straight into
- 1:41Speaker 1: a messy, unstructured web page seems like a terrible idea.
- 1:44Speaker 2: Oh absolutely, So the.
- 1:46Speaker 1: Material suggests we start with documents that are already highly structured,
- 1:49Speaker 1: specifically XML and CSV feeds.
- 1:52Speaker 2: Yeah, that's the most logical starting point. I mean, when
- 1:54Speaker 2: your target data is already organized in a strict format,
- 1:57Speaker 2: you don't need a complex navigating role. You basically just
- 2:01Speaker 2: need a specialized clerk that knows how to parse that
- 2:04Speaker 2: specific syntax.
- 2:05Speaker 1: So, looking at the first type, the XML feed spider,
- 2:08Speaker 1: I see that you point the spider in an XML file.
- 2:11Speaker 1: But then there's this property called the iterator. Yes, the
- 2:14Speaker 1: notes flag. This is a really critical configuration step. But
- 2:17Speaker 1: I'm a bit fuzzy on why is the iterator just
- 2:20Speaker 1: like a search function for the file.
- 2:22Speaker 2: No, it's far more fundamental than just a search function.
- 2:25Speaker 2: The iterator actually dictates the underlying mechanics of how the
- 2:29Speaker 2: spider physically loads and reads the file into your system's memory.
- 2:33Speaker 2: By default, scrape uses something called the it nodes iterator,
- 2:36Speaker 2: which is based on regular expression, so it streams the text,
- 2:39Speaker 2: reading it chunk by chunk, line by line, recognizing patterns
- 2:43Speaker 2: on the fly.
- 2:44Speaker 1: Wait, as opposed to what, what's the alternative if you
- 2:46Speaker 1: don't stream it?
- 2:47Speaker 2: Well, the alternative is using an HTML or XML DOM iterator.
- 2:50Speaker 2: And honestly, this is a massive trap for beginners. Really
- 2:54Speaker 2: why Because a DOM parser works by loading the entire
- 2:57Speaker 2: document into your system's ram all at once, in order
- 3:00Speaker 2: to build a complete structural tree of the data before
- 3:03Speaker 2: it even begins extracting anything.
- 3:05Speaker 1: Oh wow, Okay, I see the problem there. If I'm
- 3:08Speaker 1: scraping a supplier's product catalog and it has like four
- 3:12Speaker 1: million entries in a single XML feed, trying to load
- 3:15Speaker 1: that entire structure into memory is going to cause a
- 3:18Speaker 1: massive bottleneck.
- 3:19Speaker 2: It will completely bottleneck your system. Best case scenario, your
- 3:22Speaker 2: scraper just grinds to a halt. Worst case, you trigger
- 3:26Speaker 2: an out of memory error and crash your entire server
- 3:28Speaker 2: halfway through a critical data extraction, which is obviously bad,
- 3:31Speaker 2: very bad. And that is exactly why the streaming regular
- 3:34Speaker 2: expression method it nodes is the default. It requires vastly
- 3:37Speaker 2: less memory overhead.
- 3:39Speaker 1: That makes a lot of sense. So once you have
- 3:41Speaker 1: the memory mechanics sorted, you set your start URLs. But
- 3:44Speaker 1: then there's this other thing, the inter tag. If the
- 3:47Speaker 1: iterator is how it reads the file, what is the
- 3:50Speaker 1: inter tag actually doing.
- 3:51Speaker 2: The inter tag is essentially your target. You are telling
- 3:54Speaker 2: the spider scan the stream of data, and every time
- 3:57Speaker 2: you see a specific XML node, say a tag literally
- 4:00Speaker 2: called each product, grab that chunk of data.
- 4:02Speaker 1: Oh I get it.
- 4:03Speaker 2: Yeah, So the spider isolates that note, extracts the underlying text,
- 4:07Speaker 2: and funnels it into a custom container you've built like
- 4:10Speaker 2: a product item class.
- 4:11Speaker 1: Got it? And the CSV version the CSV feed spider
- 4:14Speaker 1: operates on a similar philosophy, right, just adapted for comma
- 4:18Speaker 1: separated values.
- 4:19Speaker 2: Exactly.
- 4:19Speaker 1: You define your headers, which map to your column names
- 4:22Speaker 1: and use a partro method to grab a specific columns
- 4:24Speaker 1: you want. But the documentation heavily highlights the quote sharp
- 4:28Speaker 1: property for csvs.
- 4:31Speaker 2: Yes, that is crucial. Why is that single property so
- 4:34Speaker 2: vital because real world data is incredibly messy. Let's say
- 4:38Speaker 2: you are extracting a column called product name. Your CSV
- 4:42Speaker 2: uses a comma as a delimiter to separate the columns.
- 4:46Speaker 2: But what if a company named their product super awesome widget.
- 4:50Speaker 1: Ah, the spider hits the comma inside the product name
- 4:53Speaker 1: and assumes it's the start of a brand new column. Yeah,
- 4:56Speaker 1: it just fractures the data right.
- 4:57Speaker 2: There, precisely, your data pipeline is instantly corrupted. So the
- 5:00Speaker 2: quote shar property tells the spider how to handle fields
- 5:03Speaker 2: that contain the delimitter inside of them.
- 5:05Speaker 1: Right.
- 5:05Speaker 2: It instructs the parser that anything wrapped in say double
- 5:09Speaker 2: quotation marks, is a single distinct value and it should
- 5:11Speaker 2: ignore any commas hidden inside.
- 5:14Speaker 1: It's basically a life saver for data integrity. So to
- 5:17Speaker 1: summarize this first tier for you, the XML and CSV
- 5:21Speaker 1: spiders are highly specialized data entry clerks. They don't click links,
- 5:25Speaker 1: they don't explore yep, they just sit at a desk
- 5:28Speaker 1: read a structured file from top to bottom and extract
- 5:31Speaker 1: the exact fields you specify.
- 5:33Speaker 2: A perfect analogy, But as you and I both know,
- 5:36Speaker 2: the Internet rarely offers up perfect XML feeds on a
- 5:39Speaker 2: silver platter. Eventually you have to scrape actual sprawling websites.
- 5:44Speaker 1: Right, which brings us to navigating multiple pages. Now, my
- 5:48Speaker 1: first instinct to scrape in entire domain would be to
- 5:50Speaker 1: write a bot that just clicks every link it sees.
- 5:53Speaker 2: Sure, that's what most people think of, But.
- 5:54Speaker 1: The architecture notes introduce the site map spider. I know,
- 5:58Speaker 1: a site map is an XML file at the of
- 6:00Speaker 1: a domain that lists out URLs, but is it really
- 6:02Speaker 1: smart to rely on that? I mean, webmasters forget to
- 6:05Speaker 1: update their site maps all the time. Aren't we blindly
- 6:08Speaker 1: trusting their infrastructure?
- 6:09Speaker 2: What's fascinating here is that, despite the risk of an
- 6:11Speaker 2: outdated site map, this is universally considered the most polite,
- 6:15Speaker 2: efficient and professional way to begin scramping a large site.
- 6:20Speaker 1: Really, even if it's outdated.
- 6:21Speaker 2: Yes, because think about the alternative. Brute force crawling requires
- 6:25Speaker 2: downloading hundreds of menu pages, pagination lists, and category hubs
- 6:30Speaker 2: just to discover the actual product pages.
- 6:32Speaker 1: So you're saving massive amounts of server overhead, both for
- 6:35Speaker 1: your own machine and for the target website by just
- 6:38Speaker 1: reading the map.
- 6:38Speaker 2: First exactly, the site is voluntarily telling you here is
- 6:42Speaker 2: a list of my content. And with sitemap spider you
- 6:45Speaker 2: get to act as a traffic cop using site mobiles.
- 6:47Speaker 1: I was looking at that the rules pair a regular
- 6:50Speaker 1: expression with a callback method. So I'm scanning the site
- 6:53Speaker 1: map URLs and if a URL contains the pattern product,
- 6:57Speaker 1: I tell the spider route this specific link to my
- 7:00Speaker 1: parse product logic, right, But if the url contains category,
- 7:04Speaker 1: I route it somewhere else entirely.
- 7:05Speaker 2: Yeah, you're basically modularizing your code. Products get scraped one way,
- 7:09Speaker 2: categories that get scraped another, and blog posts get ignored entirely.
- 7:12Speaker 2: It is totally surgical. That's really clean, and you can
- 7:15Speaker 2: get even more granular. You can utilize site mapultnate links
- 7:19Speaker 2: if you are dealing with internationalized e commerce sites and
- 7:21Speaker 2: need to chase down specific language versions of a page,
- 7:24Speaker 2: well that's smart. Or use sitemap filter to selectively drop
- 7:29Speaker 2: URLs based on custom attributes like modification dates.
- 7:32Speaker 1: Okay, I see the power there. It's incredibly fast. But
- 7:36Speaker 1: here's the reality check, site maps are a luxury.
- 7:39Speaker 2: They really are.
- 7:40Speaker 1: A lot of modern sites actively hide them or simply
- 7:43Speaker 1: don't generate them because they rely on dynamic routing. When
- 7:46Speaker 1: the map is gone, it's time to take off the
- 7:48Speaker 1: training wheels. We have to build a custom spider that
- 7:52Speaker 1: can ingest raw HTML and figure out the navigation manually.
- 7:56Speaker 2: This is where we step into the foundational screepy spider cloud.
- 8:00Speaker 2: This is where you hand code the crawler's behavior from
- 8:02Speaker 2: the absolute ground up.
- 8:04Speaker 1: Looking at the setup logic for this, we define our
- 8:06Speaker 1: star trolls, of course, but there's a huge emphasis placed
- 8:09Speaker 1: on the allowed domains property. I initially brushed past this,
- 8:12Speaker 1: but the notes make it seem like a matter of
- 8:14Speaker 1: life and death for your spider.
- 8:16Speaker 2: It absolutely is. Let's say you write a custom spider
- 8:18Speaker 2: to scrape a blog for quotes and author names. Okay,
- 8:21Speaker 2: you set it loose, but at the bottom of one
- 8:23Speaker 2: article there's a link to a Wikipedia page about the author.
- 8:26Speaker 2: Without allow domains strictly defined, your spider might follow that link,
- 8:30Speaker 2: leave the blog entirely, and suddenly attempt to download and
- 8:34Speaker 2: parse the entirety of Wikipedia.
- 8:36Speaker 1: Oh man, it just falls into a black hole of
- 8:38Speaker 1: infinite data.
- 8:39Speaker 2: And burns through your bandwidth and storage in the process.
- 8:42Speaker 2: The allowed domain's property is the leash that keeps your
- 8:45Speaker 2: spider fenced inside the specific property.
- 8:48Speaker 1: You are targeting a very necessary leash. Okay, so we
- 8:51Speaker 1: fenced the spider in and we've pointed it to the
- 8:53Speaker 1: target web page. Now we need to extract the data
- 8:56Speaker 1: from the raw HTML. We aren't using regular expressions here.
- 9:00Speaker 1: The notes specify using CSS selectors.
- 9:02Speaker 2: Yeah, that's the industry standard for this layer.
- 9:05Speaker 1: So if every quote on the web page is wrapped
- 9:07Speaker 1: in a container, say a DIV element with a class
- 9:10Speaker 1: of quote, we tell the spider find every divdut quote
- 9:14Speaker 1: on the page and loop through them exactly. And once
- 9:16Speaker 1: we isolate that box, we target the specific text inside,
- 9:19Speaker 1: maybe a span with a class of text, and pull
- 9:22Speaker 1: the data out.
- 9:23Speaker 2: You use methods like extract first to strip away the
- 9:26Speaker 2: HTML tags and leave yourself with just the raw string
- 9:29Speaker 2: of text. But remember the raw extraction is rarely pristine.
- 9:33Speaker 1: Right the data cleanup logic When you pull the tags
- 9:36Speaker 1: associated with a quote, usually get a messy list with
- 9:39Speaker 1: weird white space.
- 9:40Speaker 2: Almost always, you have to write.
- 9:42Speaker 1: Python logic inside the spider to split those words. Filter
- 9:46Speaker 1: out strange Unicode characters and maybe wrap the final string
- 9:50Speaker 1: in literal quotation marks before yielding the data to your
- 9:53Speaker 1: storage file.
- 9:54Speaker 2: It's all about transforming raw web architecture into usable data.
- 9:58Speaker 2: But once you have that extraction logic dialed in, you
- 10:01Speaker 2: encounter a behavioral quirk in Scrapy that trips up almost
- 10:04Speaker 2: every single beginner.
- 10:06Speaker 1: Oh yes, here's where it gets really interesting. I was
- 10:08Speaker 1: reviewing a sample output file in the documentation.
- 10:11Speaker 2: Yeah, out of order one.
- 10:12Speaker 1: Yes, the developer ran a custom spider across a site
- 10:15Speaker 1: with four pages of quotes. When they opened the final
- 10:18Speaker 1: text file, the quotes from page three were listed before
- 10:21Speaker 1: the quotes from page two. Page four was scattered in
- 10:23Speaker 1: the middle. The output was completely out of sequence. Did
- 10:26Speaker 1: the spider break? Did it like, skip the second page
- 10:29Speaker 1: and go back to it.
- 10:30Speaker 2: It didn't break at all. It functioned flawlessly. The confusion
- 10:34Speaker 2: just stems from human psychology. We read sequentially, page one,
- 10:39Speaker 2: then page two, then page.
- 10:40Speaker 1: Three, right, we naturally expect the program to execute that way.
- 10:43Speaker 2: Exactly, But scrapy does not process requests sequentially. It utilizes
- 10:48Speaker 2: an asynchronous, non blocking architecture.
- 10:51Speaker 1: Okay, let me pause you there. Asynchronous meaning it doesn't
- 10:55Speaker 1: wait for page two to finish downloading and extracting before
- 10:58Speaker 1: it fires off through a quest for page three.
- 11:01Speaker 2: Exactly, scrape uses an internal scheduler. When your spider discovers
- 11:06Speaker 2: the links for pages two, three, and four, it throws
- 11:08Speaker 2: all those requests into the queue and fires them off. Concurrently,
- 11:12Speaker 2: it's opening multiple network connections at once, So if the
- 11:15Speaker 2: server happens to deliver the HTML for page three a
- 11:18Speaker 2: few milliseconds faster than page two, Scrapy parses page three
- 11:21Speaker 2: and writes that data to your file immediately.
- 11:24Speaker 1: So it's basically like sending out ten runners at the
- 11:26Speaker 1: same time to fetch items for you. You don't care what
- 11:28Speaker 1: starting position they were in. The fastest runner gets back first,
- 11:31Speaker 1: hands you the item, and you put it in your
- 11:33Speaker 1: back Good. It prioritizes absolute speed over chronological order.
- 11:37Speaker 2: That is the perfect way to visualize it. It maximizes
- 11:39Speaker 2: your network resources, and since you are extracting this into
- 11:42Speaker 2: structured data formats, the out of order execution doesn't really matter.
- 11:46Speaker 2: You can instantly sort the final data set sequentially in
- 11:49Speaker 2: your database later.
- 11:50Speaker 1: Okay, I love the efficiency of that, but we kind
- 11:52Speaker 1: of skipped a vital step in the mechanics there, How
- 11:55Speaker 1: did the spider know to go to page two in
- 11:57Speaker 1: the first place.
- 11:58Speaker 2: With the CSS selectors we discussed, the spider extracts the
- 12:01Speaker 2: quotes on page one, hits the bottom of the HTML,
- 12:03Speaker 2: and just shuts down right.
- 12:06Speaker 1: To scrape a multi page site, you have to explicitly
- 12:09Speaker 1: engineer pagination logic. You have to write the code that
- 12:12Speaker 1: teaches the spider how to locate and click the next button.
- 12:15Speaker 2: Okay, So, inspecting the web page is HTML, we might
- 12:18Speaker 2: find that the next button is a list item with
- 12:20Speaker 2: a specific class like lie dot. Next, we can figure
- 12:24Speaker 2: our spider to hunt for that specific CSS selector, extract
- 12:27Speaker 2: the hyperlink the href attribute, and then what how does
- 12:30Speaker 2: it loop? Well, once the spider extracts that new URL,
- 12:34Speaker 2: it constructs a brand new request object and yields it
- 12:37Speaker 2: back to the scrapey engine. It essentially says, hey, I
- 12:41Speaker 2: found a new page. Put this in the queue, and
- 12:43Speaker 2: when it downloads, run it through this exact same parse method.
- 12:46Speaker 1: So it creates a self sustaining loop. It scrapes page two,
- 12:50Speaker 1: hunts for the next button, grabs the link for page three,
- 12:53Speaker 1: and feeds it back into the engine. Yes, it just
- 12:55Speaker 1: keeps crawling until it hits a page where the lie
- 12:59Speaker 1: dot next selector literally doesn't exist in the HTML anymore,
- 13:02Speaker 1: at which point it gracefully shuts down.
- 13:05Speaker 2: It is incredibly satisfying to watch that loop execute perfectly.
- 13:08Speaker 2: But think about the overhead here. From a development standpoint,
- 13:11Speaker 2: you the programmer, have to manually inspect the target site,
- 13:14Speaker 2: find the exact CSS selector for the pagination button, and
- 13:17Speaker 2: hardcode that loop. What happens at the site uses different
- 13:20Speaker 2: pagination styles across different categories, you'd have.
- 13:23Speaker 1: To write custom extraction rules for every single variation. That
- 13:26Speaker 1: sounds like a maintenance nightmare, which naturally leads us to
- 13:29Speaker 1: the final tier. Yeah, the crawl Spider. If we want
- 13:32Speaker 1: to map a massive domain, we can't realistically hold a
- 13:34Speaker 1: spider's hand for every single click.
- 13:36Speaker 2: Precisely, the crawl Spider is the ultimate free roaming explorer.
- 13:41Speaker 2: It is designed specifically to abstract away that tedious pagination logic.
- 13:46Speaker 1: Looking at the boilerplate code for crawl Spider, it operates
- 13:49Speaker 1: on a fundamentally different paradigm. We don't write complex recursive
- 13:52Speaker 1: loops to find buttons. The crawl Spider has a ravenous
- 13:56Speaker 1: default nature. If it seas in a tref link on
- 13:59Speaker 1: a page, it inherently wants to follow it.
- 14:01Speaker 2: It is designed for maximum discovery. To control that hunger,
- 14:04Speaker 2: we use a property called rules.
- 14:06Speaker 1: So, going back to our quotes website, instead of hunting
- 14:09Speaker 1: for lie dot next, we just set a broad rule
- 14:12Speaker 1: look at every single URL on this domain. If the
- 14:16Speaker 1: URL contains the word page, follow it, download the HTML
- 14:19Speaker 1: and route it to our extraction method.
- 14:21Speaker 2: This raises an important question, though, what happens when you
- 14:24Speaker 2: run that seemingly logical rule on a standard website.
- 14:27Speaker 1: Well, according to the case studies in the notes, you
- 14:29Speaker 1: end up with a massive data disaster. You expect maybe
- 14:32Speaker 1: fifty pages of quotes, and you end up with a
- 14:34Speaker 1: text file that is hundreds of megabytes large, filled with
- 14:37Speaker 1: duplicate entries. I was trying to figure out why the
- 14:39Speaker 1: code fail.
- 14:40Speaker 2: The code didn't fail. It executed your command flawlessly. The
- 14:44Speaker 2: problem is web architecture. Think about how a blog or
- 14:48Speaker 2: any commerce site is structured.
- 14:49Speaker 1: Oh right, The quotes aren't just listed chronologically. The site
- 14:53Speaker 1: also has category pages. It has tag pages. There's a
- 14:57Speaker 1: page for humor quotes, a page for inspirational quotes, a
- 15:00Speaker 1: page sorting by author, and all of.
- 15:02Speaker 2: Those category pages contain links with the word page in
- 15:06Speaker 2: the url structure. The crawl spider found your chronological pages,
- 15:09Speaker 2: but it also crawled every single tag page, every single
- 15:13Speaker 2: author archive, and every single category hub. It extracted the
- 15:17Speaker 2: exact same quotes from a dozen different angles because it
- 15:20Speaker 2: blindly followed every matching URL.
- 15:22Speaker 1: It's the dreaded spider trap. It didn't just pull redundant data.
- 15:26Speaker 1: It wasted our database storage and slammed the target server
- 15:29Speaker 1: with hundreds of unnecessary requests for content we already had.
- 15:32Speaker 1: This is a massive performance failure exactly.
- 15:35Speaker 2: The crawl spider is immensely powerful because it maps domains automatically,
- 15:40Speaker 2: but without severe constraints, it will wander endlessly into structural loops.
- 15:45Speaker 2: Engineering a web scraper is rarely about unleashing your tools.
- 15:48Speaker 2: It is almost entirely about knowing how to constrain them.
- 15:51Speaker 1: So how do we constrain it without going back to
- 15:53Speaker 1: the manual scrapey spider. The notes highlight an argument within
- 15:57Speaker 1: the rule definition called restricts.
- 15:59Speaker 2: Pates that is your scalpel.
- 16:01Speaker 1: So instead of letting the spider scan the entire page
- 16:03Speaker 1: for URLs that contain the word page. We apply the restriction,
- 16:08Speaker 1: we tell it only evaluate links that are physically located
- 16:11Speaker 1: inside the lie dot NEXHTML container.
- 16:14Speaker 2: By doing that, the crawl spider completely ignores the sidebar
- 16:17Speaker 2: full of category links, it ignores the foot or full
- 16:19Speaker 2: of author tags. It strictly finds the pagination button, follows
- 16:23Speaker 2: the link, and immediately stops looking for other pathways.
- 16:26Speaker 1: That is brilliant. It perfectly replicates the highly controlled, surgical
- 16:30Speaker 1: behavior of our manual, hand coded spider. But we achieved
- 16:33Speaker 1: it just by passing a single restriction rule into the
- 16:36Speaker 1: automated framework. We bypass writing complex recursive loops entirely less code,
- 16:41Speaker 1: less maintenance, exact same precise result.
- 16:44Speaker 2: It perfectly illustrates the progression of mastering this framework. You
- 16:48Speaker 2: start rigid, you learn the mechanics, and then you leverage
- 16:52Speaker 2: abstraction responsibly.
- 16:53Speaker 1: It really does. Looking back at the journey we've mapped
- 16:56Speaker 1: out today, we started with the highly structured data clerks,
- 17:00Speaker 1: the XML and CSV feed spiders that safely streamed documents
- 17:03Speaker 1: to protect our system memory. Then we move to the
- 17:06Speaker 1: map followers, the site map spider that politely leverages existing
- 17:09Speaker 1: architecture to save server overhead. From there we got into
- 17:12Speaker 1: the weeds hand coding a custom HTML navigator, using scrapey
- 17:16Speaker 1: Spider to hunt down exact CSS elements and manage a
- 17:20Speaker 1: synchronous pagination, and then the explorer exactly Finally, we unleashed
- 17:24Speaker 1: and critically tamed the fully automated crol spider.
- 17:28Speaker 2: It's a remarkably comprehensive toolkit. If you can master those
- 17:31Speaker 2: four approaches and understand the memory and network mechanics beneath them,
- 17:35Speaker 2: you can tackle virtually any static data extraction challenge on
- 17:38Speaker 2: the Internet.
- 17:39Speaker 1: Any static challenge. Before we wrap up, I have a
- 17:42Speaker 1: quick review question for you, the listener, to lock in
- 17:44Speaker 1: a critical concept from the beginning of our deep dive.
- 17:48Speaker 1: If you are trying to scrape a massive, multi gigabyte
- 17:51Speaker 1: list of products from an XML file, why should you
- 17:55Speaker 1: absolutely avoid using the dom iterator and what should you
- 17:58Speaker 1: use instead?
- 17:59Speaker 2: Think about the memory.
- 18:00Speaker 1: Right, Remember, using dom parsing attempts to load the entire
- 18:04Speaker 1: document tree into your system's RAM all at once, which
- 18:07Speaker 1: will bottle neck your memory and likely crash your scraper. Instead,
- 18:11Speaker 1: you need to rely on the default iterator it nodes,
- 18:13Speaker 1: which uses regular expressions to efficiently stream the file line by.
- 18:17Speaker 2: Line, keeping your memory footprint tiny and your pipeline stable precisely.
- 18:22Speaker 1: Now, we've sent this entire deep dive analyzing how to
- 18:25Speaker 1: parse static HTML in structured feeds, But I want to
- 18:28Speaker 1: leave you with a larger architectural concept to ponder as
- 18:30Speaker 1: you start engineering your own bots. Modern web development is
- 18:34Speaker 1: shifting dramatically.
- 18:34Speaker 2: Oh, definitely think about single page.
- 18:36Speaker 1: Applications built on frameworks like react or view. These sites
- 18:40Speaker 1: often don't serve static HTML at all. They send a
- 18:43Speaker 1: blank page and a massive bundle of JavaScript that renders
- 18:47Speaker 1: the content directly in your browser as you scroll.
- 18:49Speaker 2: Yeah, the rules completely change there.
- 18:51Speaker 1: If there is no static HTML for your CSS selectors
- 18:54Speaker 1: to target, how do you think your automated spiders will
- 18:57Speaker 1: need to evolve? What entirely different rendering tools might you
- 19:01Speaker 1: have to plug into scrapie to read a web page
- 19:03Speaker 1: that essentially builds itself in real time?
- 19:06Speaker 2: That transition from parsing static text to executing client side
- 19:10Speaker 2: code is the ultimate front tier of modern data extraction.
- 19:13Speaker 1: Definitely a puzzle to mullover as you optimize your code.
- 19:16Speaker 1: Thank you for joining us on this deep dive into
- 19:18Speaker 1: the architecture of web spiders. Keep experimenting. Respect your memory limits,
- 19:22Speaker 1: and we'll catch you on the next one.