Latest / CyberCode Academy / Course 40 - Web Scraping with Python | Episode 12: From Parsing Foundations to Scrapy Essentials
Transcript
- 0:00Speaker 1: Imagine, uh, looking at the entire Internet, like every product price,
- 0:04Speaker 1: every financial report, every real estate listing.
- 0:07Speaker 2: Right, but not as a chaotic, constantly shifting jumble of
- 0:11Speaker 2: web pages.
- 0:12Speaker 1: Exactly. Imagine it as your own personal, highly organized database.
- 0:16Speaker 1: I mean that that is the ultimate fantasy for any
- 0:19Speaker 1: data professional.
- 0:20Speaker 2: Oh absolutely, or honestly, just anyone who wants to automate
- 0:22Speaker 2: the tedious data gathering parts of their digital life.
- 0:26Speaker 1: Yeah, but how do you actually cross that bridge? Like,
- 0:29Speaker 1: how do you take the visual chaos of a modern,
- 0:32Speaker 1: heavily interactive website and efficiently extracts the exact nuggets of information.
- 0:37Speaker 2: You need without losing your mind in.
- 0:39Speaker 1: The process, right, without completely losing your mind?
- 0:42Speaker 2: Well, it is a massive conceptual leap, you know, to
- 0:45Speaker 2: go from simply browsing the web as a human to
- 0:47Speaker 2: writing code that reads the web like a machine.
- 0:50Speaker 1: Which is exactly what we're getting into in today's deep dive.
- 0:52Speaker 2: Yes, our mission today is to build a rock solid
- 0:56Speaker 2: mental model of exactly how that works. We're going to
- 0:59Speaker 2: deconstruc the architecture of web parsing.
- 1:01Speaker 1: And then we're stepping up to the heavy machinery.
- 1:03Speaker 2: Right we are. We'll move from basic targeted data extraction
- 1:08Speaker 2: to deploying production grade crawling systems using an industrial framework
- 1:12Speaker 2: called scrapie nice, and I will guide you step by
- 1:17Speaker 2: step through the terminal commands and the underlying logic so
- 1:21Speaker 2: you can visualize exactly what's happening under the hood, completely
- 1:24Speaker 2: hands free.
- 1:25Speaker 1: Okay, So we are taking the Internet and turning it
- 1:27Speaker 1: into raw material. But I mean before we can extract
- 1:30Speaker 1: the data, we really have to understand the terrain we're
- 1:33Speaker 1: operating on.
- 1:34Speaker 2: Right, You have to know how a webpage is actually built.
- 1:36Speaker 1: Yeah, because you can't successfully extract information from a building
- 1:39Speaker 1: if you don't understand the difference between, say the architect's
- 1:43Speaker 1: two dimensional blueprint and the actual physical concrete structure.
- 1:47Speaker 2: That's a great way to put it. When we talk
- 1:48Speaker 2: about reading a web page with code, we are fundamentally
- 1:52Speaker 2: talking about two very different approaches, which are HTML parsing
- 1:55Speaker 2: and DOM parsing, and knowing the difference is the first
- 2:00Speaker 2: major technical hurdle.
- 2:01Speaker 1: Okay, let's break those down.
- 2:02Speaker 2: So HTML parsing, which developers typically do with a library
- 2:06Speaker 2: like Beautiful Soup, deals entirely with static pages. It looks
- 2:10Speaker 2: exclusively at the structured text, the raw HTML.
- 2:14Speaker 1: And CSS, the stuff the server sends over the wire
- 2:16Speaker 1: the exact millisecond you request a.
- 2:18Speaker 2: URUS exactly, just the raw initial text.
- 2:21Speaker 1: Which, to be clear, Using a library for that is
- 2:23Speaker 1: a massive step up from just trying to use regular expressions.
- 2:28Speaker 2: Oh yeah, trying to use standard text search tools to
- 2:30Speaker 2: parse HTML is notoriously a nightmare for developers.
- 2:34Speaker 1: But why is that exactly? I mean, why can't I
- 2:36Speaker 1: just write a script that says find the text between
- 2:39Speaker 1: the price tags?
- 2:40Speaker 2: Because HTML is not strictly linear text, it is deeply hierarchical.
- 2:44Speaker 2: A web page is basically a nested tree of elements.
- 2:47Speaker 2: You might have a container tag, and inside that a
- 2:50Speaker 2: table tag, and inside that fifty row tags. Regular expressions
- 2:53Speaker 2: are built to read text left to right, character by.
- 2:55Speaker 1: Character, so they just get lost in the nest.
- 2:57Speaker 2: Yeah, they cannot natively understand the concept of nested hierarchies.
- 3:01Speaker 2: If a developer nests a div inside another div, a
- 3:04Speaker 2: regular expression will almost always match the wrong closing tag and.
- 3:07Speaker 1: Just and break your entire data set completely.
- 3:10Speaker 2: Break it. Beautiful soup solves this by converting that text
- 3:13Speaker 2: into an abstract syntax tree, which allows you to navigate
- 3:17Speaker 2: the static hierarchy mathematically.
- 3:19Speaker 1: But there's a catch, right, because modern websites aren't static,
- 3:22Speaker 1: not at all. If I understand correctly, If a website
- 3:25Speaker 1: uses JavaScript to load its data from an external API
- 3:28Speaker 1: after the initial page load, which I mean almost all
- 3:33Speaker 1: modern web apps do, HTML parsing is completely blind to it.
- 3:37Speaker 2: Yes. Yeah, it only sees that initial empty blueprint. Wow.
- 3:41Speaker 2: And that is the exact moment every new data extractor
- 3:44Speaker 2: hits a wall. The static htmail is really just the
- 3:47Speaker 2: script of a play.
- 3:48Speaker 1: Oh I like that. Okay, let's unpack this well.
- 3:51Speaker 2: When a modern web browser loads that script, it builds
- 3:54Speaker 2: something called the document object model or the DOM. The
- 3:57Speaker 2: DOM right, Yeah, this is a complex hierarchical tree structure
- 4:00Speaker 2: that the browser sets up in its memory. It's a
- 4:02Speaker 2: living object oriented representation of the page. Then the JavaScript executes.
- 4:07Speaker 1: So, if the HTML is the script, the JavaScript is
- 4:10Speaker 1: the actors.
- 4:11Speaker 2: The actors improvising on stage. The JavaScript interacts with the
- 4:14Speaker 2: DOM objects, pulls in new data from hidden APIs, moves
- 4:18Speaker 2: elements around, and essentially changes the story on the fly.
- 4:21Speaker 1: So if HTML parsing is reading the script, DOM parsing
- 4:25Speaker 1: is sitting in the theater watching the actors perform. The
- 4:28Speaker 1: final improvised scene.
- 4:30Speaker 2: What's fascinating here is that you've diagnosed the problem perfectly.
- 4:33Speaker 1: So if I'm looking at a modern dynamic site, I
- 4:37Speaker 1: see the data on my screen, but my simple HTML
- 4:41Speaker 1: scraper just comes back with a blank.
- 4:42Speaker 2: File because it left the theater before the actors even
- 4:45Speaker 2: walked on stage.
- 4:46Speaker 1: Oh man, that is so frustrating. So how do we
- 4:49Speaker 1: actually get the data?
- 4:50Speaker 2: Then? To get that data you have to use dom parsing.
- 4:53Speaker 2: You use tools like Selenium or Playwright, which actually spin
- 4:56Speaker 2: up a real automated web browser in the background, like
- 4:59Speaker 2: a hidden browse, exactly a headless browser to execute the
- 5:02Speaker 2: JavaScript and build that live tree structure.
- 5:05Speaker 1: But you know, if you're listening to this and thinking, well,
- 5:06Speaker 1: if don parsing reads the final dynamic data, why not
- 5:09Speaker 1: just use Selenium for absolutely everything? There has to be
- 5:12Speaker 1: a catch. I'm guessing it comes down to compute.
- 5:14Speaker 2: Overhead, A massive compute overhead. Yeah, requesting a static HTML
- 5:18Speaker 2: file takes kilobytes of data and a few milliseconds of processing.
- 5:23Speaker 1: Power, practically nothing right.
- 5:26Speaker 2: But running a full headless instance of Google Chrome via
- 5:29Speaker 2: Selenium to render a dom that takes hundreds of megabytes
- 5:32Speaker 2: of RAM and significant CPU cycles.
- 5:35Speaker 1: Oh wow, So if you need to scrape one page, fine,
- 5:38Speaker 1: but if.
- 5:39Speaker 2: You need to scrape one hundred thousand pages, DOM parsing
- 5:42Speaker 2: will literally melt your machine unless you have a server farm.
- 5:45Speaker 1: Yeah, that makes sense. And if we want to get
- 5:46Speaker 1: really extreme and like step outside of reading the code entirely,
- 5:50Speaker 1: there is actually a third path right computer vision.
- 5:53Speaker 2: There is applications like secul life for example. They don't
- 5:56Speaker 2: parse HTML or the DOM at all.
- 5:58Speaker 1: What do they do?
- 5:59Speaker 2: They use compute to visually identify user interface elements on
- 6:03Speaker 2: the screen. It automates the graphical interface just like a
- 6:07Speaker 2: human eye would.
- 6:08Speaker 1: Wait, really, it literally looks at the screen.
- 6:10Speaker 2: Yeah, it looks for the pixel shape of a button
- 6:12Speaker 2: or the visual layout of a textbox.
- 6:14Speaker 1: So we are bypassing the code entirely. But isn't visual
- 6:18Speaker 1: partsing incredibly slow and computationally expensive compared to just reading
- 6:22Speaker 1: a DOM tree massively.
- 6:24Speaker 2: It is definitely the brute force method of last resort,
- 6:27Speaker 2: and it's highly sensitive to things like screen resolution changes
- 6:32Speaker 2: or slight UI updates.
- 6:33Speaker 1: So if a button moves two pixels to the left, it.
- 6:36Speaker 2: Breaks pretty much. So as a data professional, you always
- 6:39Speaker 2: want to stay as close to the raw code as possible.
- 6:42Speaker 1: Okay, that makes sense. So if we know how to
- 6:44Speaker 1: read the code, whether we are pulling the lightweight static
- 6:48Speaker 1: HTML or rendering the heavy dynamic DOM, what stops me
- 6:51Speaker 1: from just pointing a script at the entire Internet and
- 6:54Speaker 1: downloading it all.
- 6:55Speaker 2: Ah Well, this brings up a critical distinction in the
- 6:57Speaker 2: scope of the job, webscraping versus web.
- 7:00Speaker 1: Crawling, which people mix up all the time constantly.
- 7:03Speaker 2: The terms are often used interchangeably, but technologically they require
- 7:06Speaker 2: completely different infrastructures. How So, webscraping is targeted. It is
- 7:10Speaker 2: usually small scale, highly specific, direct extraction. You are looking
- 7:14Speaker 2: for a very specialized.
- 7:16Speaker 1: Data set, like writing a script to grab all the
- 7:19Speaker 1: laptop prices from an e commerce competitive directly. Now, because
- 7:23Speaker 1: of use cases like that, webscraping sometimes carries a somewhat
- 7:27Speaker 1: unsavory reputation in the tech world. But I had to
- 7:30Speaker 1: push back on that go ahead. If I'm just writing
- 7:32Speaker 1: a script to check competitor prices, isn't that just automated
- 7:36Speaker 1: window shopping, like a human could sit there, click through
- 7:39Speaker 1: the pages and write the prices down on a notepad.
- 7:42Speaker 1: Why does the automated version get a bad wrap?
- 7:44Speaker 2: It really comes down to intent and infrastructure strain.
- 7:48Speaker 1: The strain on their servers.
- 7:50Speaker 2: Right, there is absolutely nothing inherently wrong with webscraping, But
- 7:54Speaker 2: when it's poorly written, you might have millions of bots
- 7:58Speaker 2: hitting a server thousands of times a seat just to
- 8:00Speaker 2: rip proprietary data.
- 8:02Speaker 1: Oh yikes, Yeah, they don't respect the server's bandwidth limits exactly. Yeah.
- 8:06Speaker 2: Web crawling, on the other hand, is fundamentally different in
- 8:09Speaker 2: scope and is generally associated with foundational internet architecture.
- 8:12Speaker 1: Like search engines.
- 8:14Speaker 2: Yes, crawling has a much broader scope and his general purpose.
- 8:18Speaker 2: Web crawling involves downloading a web page, extracting the information,
- 8:23Speaker 2: and then recursively finding every single link on that page
- 8:27Speaker 2: to map the connections.
- 8:28Speaker 1: So it's not just a big net you throw over
- 8:30Speaker 1: a website.
- 8:31Speaker 2: No, crawling is more like entering a massive labyrinth. You
- 8:34Speaker 2: open a door, write down everything inside the room, find
- 8:37Speaker 2: three new keys, and use those keys to open three
- 8:40Speaker 2: more doors.
- 8:42Speaker 1: That sounds incredibly complicated To keep track of it is.
- 8:45Speaker 2: Crucially you have to maintain a massive mathematical ledger, often
- 8:50Speaker 2: using complex data structures like bloom filters, just to remember
- 8:53Speaker 2: where you've been exactly, To keep track of which doors
- 8:56Speaker 2: you've already opened, so your crawler doesn't get caught in
- 8:58Speaker 2: an infinite loop walking in circles.
- 9:00Speaker 1: Okay, I see the scale difference. Now. Scraping is walking
- 9:03Speaker 1: into a grocery store with a specific list, get the
- 9:06Speaker 1: price of milk and.
- 9:07Speaker 2: Leave, and crawling is mapping the entire labyrinth of the
- 9:10Speaker 2: Internet to build a search engine.
- 9:12Speaker 1: Wow. And if you want to navigate that labyrinth that scale,
- 9:15Speaker 1: you have to upgrade your tools, right. I mean you
- 9:17Speaker 1: can't just use a simple parsing library like beautiful Soup for.
- 9:20Speaker 2: That, No, not at all. Managing the memory of URLs
- 9:24Speaker 2: you visited, Managing proxy pools so your IP address doesn't
- 9:27Speaker 2: get banned respecting a website's robots dot txt rules. That
- 9:32Speaker 2: requires an industrial application framework.
- 9:35Speaker 1: And this is where Scrapie enters the picture.
- 9:37Speaker 2: This where Scrapey shines.
- 9:38Speaker 1: But to build that maze runner, I can't just import
- 9:41Speaker 1: scrape into my existing Python script like a normal tool.
- 9:44Speaker 2: Right.
- 9:45Speaker 1: There's a structural difference here, a profound one.
- 9:48Speaker 2: To understand scrape you really have to understand the fundamental
- 9:51Speaker 2: difference between a library and a framework, Okay. And that
- 9:54Speaker 2: comes down to a software engineering concept called inversion of control.
- 9:58Speaker 1: Inversion of control. Here's where it gets really interesting. That
- 10:02Speaker 1: sounds like a sci fi movie troop where the AI
- 10:05Speaker 1: takes over the ship. What does that actually mean for
- 10:07Speaker 1: the architecture of my code.
- 10:09Speaker 2: Well, when you use a library, you are writing the application.
- 10:13Speaker 2: You're in the driver's seat. Your code runs line by line,
- 10:16Speaker 2: and when you need a specific task done, like parsing
- 10:19Speaker 2: a string, your code calls the library's function, waits for
- 10:22Speaker 2: the result, and continues standard programming exactly. But with a
- 10:26Speaker 2: framework like Scrapie, the framework is the application. The framework
- 10:31Speaker 2: is in the driver's seat. Whoa yeah, it defines the
- 10:34Speaker 2: entire structure, the event loops, the error handling. You just
- 10:37Speaker 2: write tiny bits of custom code and the framework called
- 10:40Speaker 2: your code at the exact right moment. Control is inverted.
- 10:44Speaker 1: So if I'm understanding this right, a library is like
- 10:48Speaker 1: a toolbox. I have to build the house myself, swing
- 10:51Speaker 1: the hammer, measure the wood, and I just reach into
- 10:54Speaker 1: the toolbox for the specific wrench.
- 10:56Speaker 2: I need perfect analogy.
- 10:57Speaker 1: But a framework is like hiring a general car contractor.
- 11:00Speaker 1: They run the entire job site, they manage the schedule,
- 11:03Speaker 1: they hire the crew. I just hand them the blueprints
- 11:05Speaker 1: for the specific rooms. I want, and they come to
- 11:07Speaker 1: me when they need my approval.
- 11:09Speaker 2: Taking that contractor analogy a step further. Scrapeye specifically runs
- 11:13Speaker 2: an asynchronous event loop built on a technology called twisted Twisted.
- 11:17Speaker 1: Okay, why is that crucial?
- 11:18Speaker 2: It's crucial for crawling. In a normal script, if you
- 11:21Speaker 2: request a web page, your code stops and waits for
- 11:24Speaker 2: the server to respond. It sits idle, just burning time. Right.
- 11:29Speaker 2: Scrapey doesn't do that because it controls the execution flow.
- 11:33Speaker 2: It can fire off one hundred network requests simultaneously.
- 11:36Speaker 1: One hundred at once.
- 11:37Speaker 2: Oh yeah, and while it's waiting for those network packets
- 11:40Speaker 2: to travel across the country, it doesn't wait around. It
- 11:43Speaker 2: instantly switches to processing. The HTML had already downloaded from
- 11:47Speaker 2: a previous request.
- 11:48Speaker 1: So instead of ordering a coffee, waiting at the counter
- 11:50Speaker 1: and then ordering a pastry, Scrapie places one hundred coffee orders,
- 11:54Speaker 1: steps back, and just catches whichever cup the buruster throws out.
- 11:58Speaker 2: It first and processes it instantly. Yeah, that explains how
- 12:01Speaker 2: it achieves such massive scale.
- 12:03Speaker 1: That is wild.
- 12:04Speaker 2: Scrapey handles all that asynchronous networking behind the scenes. You
- 12:08Speaker 2: just define a class called a spider, which contains your
- 12:11Speaker 2: specific extraction.
- 12:12Speaker 1: Logic the glueprints for the rooms exactly.
- 12:15Speaker 2: But even with a massive general contractor managing the network requests,
- 12:19Speaker 2: the actual extraction part, telling the spider exactly what data
- 12:22Speaker 2: to grab can still be incredibly fragile.
- 12:25Speaker 1: Right because we are back to reading the HTML structure.
- 12:28Speaker 1: How do we actually point the spider to the data?
- 12:31Speaker 2: You have to specify selectors. A selector is basically a
- 12:34Speaker 2: highly specific map pointing to an HTML element on the page.
- 12:38Speaker 1: Like go here.
- 12:39Speaker 2: Yeah. Scrapye supports using CSS class names, which are the
- 12:43Speaker 2: attributes defining how an element looks, or XPath expressions.
- 12:47Speaker 1: What's XPath?
- 12:49Speaker 2: XPath is a query language that navigates down the hierarchical
- 12:52Speaker 2: HTML tree. It's like giving turn by turn directions. Go
- 12:56Speaker 2: to the root node, find the third div container, enter
- 12:59Speaker 2: the set and table, and extract the text inside the boldtag.
- 13:04Speaker 1: Wow. Okay, But think about what happens if the web
- 13:06Speaker 1: developer decides to redesign their site tomorrow, Like they change
- 13:10Speaker 1: the CSS class name from price tag to cost label,
- 13:13Speaker 1: or they add a promotional banner at the top of
- 13:15Speaker 1: the page which pushes that table down, shifting the entire
- 13:18Speaker 1: XPath hierarchy down one level.
- 13:20Speaker 2: Then the map is suddenly pointing.
- 13:21Speaker 1: To the wrong city and the spider brakes.
- 13:23Speaker 2: The spider breaks instantly. Because targeted data extraction relies on
- 13:27Speaker 2: the structural integrity of the HTML, using tools like scrapy
- 13:30Speaker 2: requires constant maintenance, so.
- 13:32Speaker 1: If the website changes, your code has to change exactly.
- 13:35Speaker 2: It is a constant arms race between web developers and
- 13:38Speaker 2: data engineers.
- 13:39Speaker 1: All right, so we know the risks, we know the architecture.
- 13:42Speaker 1: I think it's time we actually get our hands dirty.
- 13:44Speaker 2: Let's do it.
- 13:45Speaker 1: Let's imagine we are sitting right in front of the terminal,
- 13:48Speaker 1: staring at a blinking cursor, ready to fire up this
- 13:52Speaker 1: asynchronous general contractor we just hired. How do we actually
- 13:56Speaker 1: operate scrapey from the command line?
- 13:59Speaker 2: Well, command line interface is where Scrapy's power becomes immediately visible.
- 14:03Speaker 2: Let's assume you have the framework installed and ready to go.
- 14:06Speaker 2: A great place to start is just testing what your
- 14:09Speaker 2: machine and network can actually handle by typing scrapey bench.
- 14:13Speaker 1: Like benchmarking a video game to see if your graphics
- 14:15Speaker 1: card will.
- 14:16Speaker 2: Melt exactly, but for asynchronous io limits. Scrapy dunch spins
- 14:21Speaker 2: up a local web server right there on your machine,
- 14:23Speaker 2: and then unleashes its own crawler against it as fast
- 14:27Speaker 2: as your hardware allowed.
- 14:28Speaker 1: Oh that's cool.
- 14:28Speaker 2: Yeah, it floods your terminal with real time statistics. You'll
- 14:31Speaker 2: see it tracking the raw number of HTTP requests made,
- 14:34Speaker 2: the responses received, the exact bike counts flowing back and forth.
- 14:38Speaker 1: So you might see that your specific laptop can handle
- 14:41Speaker 1: I don't know, crawling three thousand pages a minute.
- 14:44Speaker 2: Right. It gives you a baseline for your heavy machinery
- 14:46Speaker 2: before you point it at the real Internet.
- 14:48Speaker 1: That is highly practical. But let's look outward. If I
- 14:51Speaker 1: want to point this at an actual target, how do
- 14:54Speaker 1: I do that?
- 14:54Speaker 2: We use the fetch command. Let's say we want to
- 14:57Speaker 2: look at a specific tech forum. You type scrape fetch
- 15:00Speaker 2: followed by the URL, and what happens by default scrapey
- 15:04Speaker 2: hits the URL, downloads the HTML content, and spits the
- 15:08Speaker 2: raw code directly onto your terminal screen.
- 15:10Speaker 1: Just a huge wall of texts, Just.
- 15:11Speaker 2: A massive wall of texts scrolling past. But using standard
- 15:15Speaker 2: terminal commands, you can redirect that output into a local file,
- 15:18Speaker 2: saving it on your hard drive as an HTML document.
- 15:21Speaker 1: Okay, so I've ripped the HTML off the server and
- 15:23Speaker 1: I have it on my hard drive. But reading raw
- 15:26Speaker 1: HTML and a text editor isn't exactly intertive for figuring
- 15:29Speaker 1: out my expath selectors. How do I know what the
- 15:31Speaker 1: spider is actually seeing?
- 15:33Speaker 2: That is what the scrapeyview command is for, and it
- 15:36Speaker 2: is arguably your most powerful debugging tool.
- 15:39Speaker 1: Screepyview.
- 15:40Speaker 2: Yeah, you type scrapeyview in the URL. Scrapey downloads the
- 15:43Speaker 2: target URL, caches it as a file on your local machine,
- 15:46Speaker 2: and then automatically opens your default web browser pointing to
- 15:49Speaker 2: that local file, not the live internet.
- 15:51Speaker 1: Wait, why does it do that? Why not just show
- 15:53Speaker 1: me the live site?
- 15:54Speaker 2: Because it wants to force you to confront with the
- 15:56Speaker 2: static scraper actually sees stripped of its dynamic illusions. When
- 16:00Speaker 2: scrapeye downloads that local file and opens it, your browser
- 16:04Speaker 2: attempts to run the web page's JavaScript, But because that
- 16:07Speaker 2: script is no longer connected to the live server's database API,
- 16:11Speaker 2: or because security protocols.
- 16:12Speaker 1: Block it, the JavaScript panics exactly.
- 16:15Speaker 2: It fails to execute, and the page often renders completely broken,
- 16:19Speaker 2: missing images, or with completely empty data tables.
- 16:22Speaker 1: So what does this all mean? If I run scrapyview
- 16:25Speaker 1: on a heavily dynamic site and the page opens looking
- 16:28Speaker 1: totally broken. That's actually a good thing, right, very good,
- 16:30Speaker 1: because it proves my data isn't in the raw HTML.
- 16:33Speaker 1: It's a massive warning sign telling me the site relies
- 16:35Speaker 1: on dynamic dam rendering and I need to handle that
- 16:39Speaker 1: before I spend three hours writing a spider that is
- 16:41Speaker 1: going to fail.
- 16:42Speaker 2: Yes, if we connect this to the bigger picture, seeing
- 16:46Speaker 2: a broken page in scrapeyview saves you hours of frustration.
- 16:51Speaker 2: It acts as an X ray, stripping away the JavaScript
- 16:54Speaker 2: so you can see if the actual data bones are
- 16:56Speaker 2: present in the HTML skeleton, and if.
- 16:58Speaker 1: The skeleton is missing a leg. You know you have
- 17:01Speaker 1: a problem before you start trying to make.
- 17:02Speaker 2: It run exactly. It's brilliant.
- 17:05Speaker 1: Are there any other core commands we need to know
- 17:07Speaker 1: before we start writing extraction logic?
- 17:09Speaker 2: You will constantly use scrapey settings because Scrapie is managing
- 17:13Speaker 2: the entire crawling infrastructure. You have to configure its behavior
- 17:17Speaker 2: like what kind of behavior, things like concurrent requests, how
- 17:20Speaker 2: many network connections it opens at once, or auto throttle,
- 17:24Speaker 2: which automatically slows down the crawler if it detects the
- 17:26Speaker 2: target server is struggling to keep up.
- 17:29Speaker 1: Oh that's nice, ensuring you don't accidentally execute a denial
- 17:32Speaker 1: of service attack.
- 17:33Speaker 2: Right. You also use settings to rotate user agents, which
- 17:36Speaker 2: tells the server what kind of browser you are pretending
- 17:38Speaker 2: to be. But here's the catch. If you run scrapey
- 17:42Speaker 2: settings right out of the box, it returns absolutely nothing.
- 17:46Speaker 1: Really, it operates entirely on hidden defaults until you explicitly
- 17:49Speaker 1: configure it correct.
- 17:51Speaker 2: It waits for you to define the rules of engagement.
- 17:53Speaker 1: Wow, this completely reframes how you look at the web.
- 17:57Speaker 1: We covered some serious technical ground today, We really did.
- 18:00Speaker 1: We started with the foundational difference between the static HTML
- 18:03Speaker 1: blueprint and the live JavaScript render dom theater. We explored
- 18:08Speaker 1: why visual parsing is too expensive and why the scale
- 18:11Speaker 1: of web trawling requires managing state and deduplicating URLs as
- 18:15Speaker 1: you navigate the labyrinth of the Internet.
- 18:17Speaker 2: We also detail the inversion of control, the concept that
- 18:21Speaker 2: elevates scrapeye into a fully managed a syncretoust general contractor
- 18:25Speaker 2: driven by the twisted event.
- 18:26Speaker 1: Loop, and we looked at how fragile those XPath selectors
- 18:30Speaker 1: can be and how to operate the framework from the
- 18:32Speaker 1: command line using bench fetch and the x ray vision
- 18:35Speaker 1: of scrapey view. It's a lot to take care it is,
- 18:38Speaker 1: so to make sure this mental model really sticks. Here
- 18:41Speaker 1: is a practical review exercise for you. Next time you
- 18:43Speaker 1: visit your favorite e commerce site, write click on the
- 18:46Speaker 1: page and select view paid source.
- 18:48Speaker 2: Good exercise.
- 18:49Speaker 1: Look closely at the raw code. Ask yourself, am I
- 18:52Speaker 1: actually looking at static HTML that contains the product data?
- 18:56Speaker 1: Or is this all DOM content being injected on the
- 18:59Speaker 1: fly by an API. Based on your answer, would you
- 19:02Speaker 1: choose a light rate HQML parser or would you need
- 19:04Speaker 1: to build a heavy duty DOM renderer to extract that data?
- 19:08Speaker 2: And that leads to a critical technical question that I
- 19:11Speaker 2: want to leave you with. We discussed how building webscrapers
- 19:14Speaker 2: based on HTML structure is inherently fragile because developers change
- 19:18Speaker 2: class names and layouts.
- 19:19Speaker 1: Right.
- 19:19Speaker 2: But as artificial intelligence becomes more deeply integrated into web development,
- 19:23Speaker 2: what happens when servers begin to dynamically generate entirely unique
- 19:27Speaker 2: HTML structures on the fly for every single individual user
- 19:30Speaker 2: session in real time?
- 19:32Speaker 1: Oh wow?
- 19:32Speaker 2: How will our a secretis? Frameworks and our data extraction
- 19:35Speaker 2: strategies have to evolve to read a web that actively
- 19:38Speaker 2: mutates its own code to avoid being parsed.
- 19:40Speaker 1: A web that actively shifts its blueprint while you're trying
- 19:43Speaker 1: to read it. That turns the fantasy of a perfectly
- 19:46Speaker 1: structured personal database into an infinitely moving target. But hey,
- 19:50Speaker 1: that is a data engineering problem for the next deep dive.
- 19:53Speaker 1: Keep crawling, keep extracting, and we will catch you next time.