Latest / CyberCode Academy / Course 40 - Web Scraping with Python | Episode 37: Integrating Selenium and Beautiful Soup
Transcript
- 0:00Speaker 1: So picture this. You've written a scraping script to pull
- 0:05Speaker 1: some highly specific data from a modern web app, right.
- 0:09Speaker 2: Like maybe you're analyzing market trends or I don't know,
- 0:11Speaker 2: tracking inventory exactly.
- 0:14Speaker 1: But the data isn't just sitting there in some nice
- 0:17Speaker 1: static HTML file waiting to be grabbed.
- 0:19Speaker 2: Oh definitely not. Usually it's buried behind a client side
- 0:22Speaker 2: JavaScript rendering engine.
- 0:23Speaker 1: Yeah, or like hidden behind drop down menu, search queries,
- 0:27Speaker 1: authentication walls, all that stuff.
- 0:29Speaker 2: Right. And you know that data is physically there in
- 0:31Speaker 2: your browser's memory, right, you can see it on.
- 0:33Speaker 1: The screen, But if you try to extract it using
- 0:36Speaker 1: a standard automated script, your code just suddenly bam, grinds
- 0:40Speaker 1: to an absolute halt.
- 0:41Speaker 2: It's incredibly frustrating.
- 0:42Speaker 1: It really is. So for today's deep dive, we're looking
- 0:45Speaker 1: at why bypassing your browser's native language is kind of
- 0:48Speaker 1: the only way to get that data out efficiently.
- 0:50Speaker 2: Yeah, and we'll look at how combining Python, Selenium and
- 0:53Speaker 2: beautiful Soup builds this architecture that solves this exact bottleneck.
- 0:59Speaker 1: Which is so u because I mean, most developers run
- 1:02Speaker 1: into this wall the exact moment they graduate from scraping
- 1:05Speaker 1: simple static pages oh.
- 1:06Speaker 2: Absolutely. The minute you try interacting with real world dynamic applications,
- 1:11Speaker 2: things change.
- 1:13Speaker 1: Because a basic HTTP request to a modern site often
- 1:16Speaker 1: just returns like a skeleton HTML file, right.
- 1:19Speaker 2: Exactly, just a skeleton with a bunch of JavaScript tags.
- 1:22Speaker 2: The data isn't even there yet.
- 1:23Speaker 1: You actually need a real browser environment to execute that
- 1:26Speaker 1: JavaScript and render the actual document object model or the DOM.
- 1:32Speaker 2: Right. So naturally the instinct is to just bring in Selenium.
- 1:36Speaker 1: Because Selenium controls a real web browser, it can click buttons,
- 1:39Speaker 1: bypass pop ups, type.
- 1:40Speaker 2: Into fields yeah, and it can wait for the JavaScript
- 1:43Speaker 2: to execute it as functions build right into it to
- 1:45Speaker 2: locate elements and extract their text.
- 1:48Speaker 1: Right. So, if Selenium can do all of that, a
- 1:50Speaker 1: lot of developers learning web automation naturally wonder why don't
- 1:54Speaker 1: we just use it for the entire data extraction process.
- 1:57Speaker 2: I mean, it seems totally logical at first glance, because
- 2:00Speaker 2: the capability to read the DOM is absolutely built into Selenium.
- 2:04Speaker 2: You can target a specific paragraph tag and extract the
- 2:08Speaker 2: text string right out of.
- 2:09Speaker 1: It, So why not just do that for everything?
- 2:11Speaker 2: Well, relying on Selenium to extract large data sets is
- 2:15Speaker 2: actually an architectural trap.
- 2:17Speaker 1: Okay, an architectural trap.
- 2:18Speaker 2: How so the issue isn't capability, you know, it's the
- 2:22Speaker 2: immense serialization overhead HATCHA. To really understand the bottleneck, we
- 2:27Speaker 2: have to look at the W three C webdriver protocol
- 2:30Speaker 2: that powers it under the hood.
- 2:32Speaker 1: Right, let's get into the mechanics of that. Because your
- 2:35Speaker 1: Python script and say the Chrome or Firefox browser it's controlling,
- 2:39Speaker 1: they aren't actually running in the same memory space exactly.
- 2:42Speaker 2: They are completely separate entities. Your Python environment cannot directly
- 2:47Speaker 2: read the RAM allocated to the web browser.
- 2:49Speaker 1: Okay, so how do they talk?
- 2:51Speaker 2: They have to communicate over a network protocol. Historically this
- 2:54Speaker 2: was known as the JSON wire protocol. Okay, So when
- 2:57Speaker 2: you tell Selenium to find an element and get it's text,
- 3:00Speaker 2: it doesn't just like read a local variable.
- 3:03Speaker 1: It's essentially texting a middleman.
- 3:05Speaker 2: That's a great way to put it.
- 3:06Speaker 1: Like it's like needing to read a massive encyclopedia, but
- 3:09Speaker 1: the book is locked in a library completely across town,
- 3:13Speaker 1: and instead of just going there yourself, you hire someone
- 3:16Speaker 1: to stand in the library and you text them, like,
- 3:18Speaker 1: turn to page one, read line one, text it back
- 3:21Speaker 1: to me.
- 3:22Speaker 2: Yeah, that is a highly accurate way to visualize the latency.
- 3:25Speaker 2: Every single interaction involves packaging your command into a JSON
- 3:29Speaker 2: payload wow, then opening an HTTP connection to the browser
- 3:35Speaker 2: driver like Chrome driver or Gecko driver, which then executes
- 3:39Speaker 2: the command inside the browser's JavaScript engine.
- 3:42Speaker 1: So it's literally sending it over the network every single
- 3:44Speaker 1: time exactly.
- 3:45Speaker 2: The browser finds the text, passes it back to the driver,
- 3:48Speaker 2: which serializes it back into a JSON response.
- 3:51Speaker 1: And sends it back over HTTP to your Python script.
- 3:54Speaker 2: Right, and then your script finally has to de serialize it.
- 3:56Speaker 1: Which I mean sounds fast enough for a single query.
- 3:58Speaker 2: You're sure, for one query, it's fine, But let's do.
- 4:00Speaker 1: The math on a real world's grading task. Say you're
- 4:03Speaker 1: pulling a data table with one thousand rows and five columns.
- 4:06Speaker 1: Oh boy, Yeah, if you use Selenium to iterate through
- 4:09Speaker 1: every single cell to extract the text, you are making
- 4:12Speaker 1: five thousand separate HTTP network request.
- 4:15Speaker 2: Just to read data that is already sitting right there
- 4:18Speaker 2: on your local machine. That's insane, and that is the
- 4:21Speaker 2: hidden text that communication overhead snowballs so incredibly fast. Yeah,
- 4:26Speaker 2: a script that should take milliseconds ends up taking three
- 4:29Speaker 2: or four minutes to execute. You're just bottlenecking your CPU
- 4:33Speaker 2: with constant network serialization and de serialization delays.
- 4:37Speaker 1: Okay, so if the whole texting the middleman approach fails
- 4:41Speaker 1: at scale, we need a way to just grab the
- 4:45Speaker 1: entire encyclopedia, bring it back to our own workspace, and
- 4:48Speaker 1: flip through the pages.
- 4:49Speaker 2: Ourselves, right at top speed.
- 4:50Speaker 1: Exactly, which brings us to the parsing phase and our
- 4:53Speaker 1: local speed reader. Beautiful Soup.
- 4:56Speaker 2: Yes, Beautiful Soup is designed specifically for this local extra
- 5:00Speaker 2: action phase.
- 5:00Speaker 1: Just to define it simply, it's a Python library that
- 5:03Speaker 1: pulls data out of HTML and XML files right exactly.
- 5:07Speaker 2: Rather than communicating across a network protocol, it takes the
- 5:11Speaker 2: raw HTML text and structures it locally in your Python
- 5:14Speaker 2: environment's memory, so.
- 5:16Speaker 1: You could just traverse it instantly. Chris, But you know,
- 5:19Speaker 1: before we even talk about how beautiful soupstructure is the memory,
- 5:21Speaker 1: I kind of want to play Devil's Advocate for a second.
- 5:23Speaker 2: Sure, go for it.
- 5:24Speaker 1: If parsing EACHTML is technically just string manipulation and we
- 5:29Speaker 1: have the whole HTML file locally, why pull in a
- 5:33Speaker 1: dedicated library at all?
- 5:35Speaker 2: Ah? The classic developer question.
- 5:37Speaker 1: Right, like, why couldn't I just write a few clever
- 5:40Speaker 1: regular expressions in Python to find the data I need.
- 5:42Speaker 2: It is a temptation every developer faces, and I'll tell
- 5:45Speaker 2: you it usually ends in.
- 5:47Speaker 1: Total disaster, really total disaster.
- 5:50Speaker 2: Yeah, because HTML is not a regular language. It features
- 5:53Speaker 2: nested recursive structures. Ah.
- 5:56Speaker 1: Right.
- 5:56Speaker 2: If you write a rejex to find a specific divtag
- 5:59Speaker 2: and the way websites developer and nested another div inside of.
- 6:02Speaker 1: It, well they just forgot to close the tag entirely,
- 6:04Speaker 1: which happens all.
- 6:05Speaker 2: The time exactly. Your rejects will break instantly or just
- 6:08Speaker 2: return garbage data. Beautiful soup doesn't just read the string.
- 6:12Speaker 2: It actually analyzes the syntax and.
- 6:14Speaker 1: Builds a structural representation of the document, right, which is
- 6:16Speaker 1: known as a parse tree.
- 6:18Speaker 2: Exactly. It turns this chaotic wall of text into a
- 6:22Speaker 2: navigable hierarchy.
- 6:24Speaker 1: Which is so much safer. Yeah, and speaking of chaos,
- 6:27Speaker 1: let's talk about the encoding nightmare. Oh yes, because before
- 6:30Speaker 1: you even worry about parsing syntax, just the sheer act
- 6:33Speaker 1: of importing web data can completely mangle your text.
- 6:37Speaker 2: Absolutely.
- 6:38Speaker 1: Anyone who has scraped international sites knows the pain of
- 6:42Speaker 1: seeing like currency symbols turn into hollow boxes.
- 6:45Speaker 2: Or apostrophes turning into weird question marks. It's character encoding mismatches. Yeah,
- 6:51Speaker 2: a web server might send you data encoded in Windows
- 6:53Speaker 2: twelve five to two or ISO eight eight five nine
- 6:56Speaker 2: one right.
- 6:57Speaker 1: And if your Python environment is strictly expecting utfa E.
- 7:00Speaker 2: It totally fails to map the raw bites to the
- 7:02Speaker 2: correct characters.
- 7:03Speaker 1: Which is a huge headache. But this brings up one
- 7:06Speaker 1: of the most powerful, yet kind of invisible features of
- 7:10Speaker 1: Beautiful Soup.
- 7:11Speaker 2: Yes, the sublibrary it uses and it's called unicode dam it.
- 7:15Speaker 1: Yeah. Wait, is that genuinely the name of the library?
- 7:18Speaker 2: It is, Yeah, and honestly it completely earns the name.
- 7:21Speaker 1: That's hilarious. How does it work?
- 7:22Speaker 2: When you pass raw HTML into Beautiful Soup, Unicode dam
- 7:26Speaker 2: it actively sniffs the document from meta tags to detect
- 7:29Speaker 2: the original encoding. It then automatically converts those incoming bytes
- 7:34Speaker 2: into standard Unicode for internal processing.
- 7:36Speaker 1: So it does it all for you.
- 7:37Speaker 2: Yep, And it ensures that any output you generate is
- 7:41Speaker 2: cleanly encoded in UTF eight.
- 7:42Speaker 1: So it just normalizes the byte data automatically. You don't
- 7:45Speaker 1: have to manually write like trixcept blocks to guess if
- 7:48Speaker 1: a page is in Latin one.
- 7:49Speaker 2: Or whatever exactly. It just hands you clean text. You
- 7:52Speaker 2: rarely have to think about encodings at all.
- 7:54Speaker 1: That is such a lifesaver. Is there ever a time
- 7:57Speaker 1: it fails?
- 7:58Speaker 2: The only real exception is if the ver provides literally
- 8:01Speaker 2: no encoding metadata and the byte sequence is entirely ambiguous.
- 8:05Speaker 1: Okay, so that's pretty rare.
- 8:06Speaker 2: Yeah, only then might you have to manually specify the format.
- 8:10Speaker 2: But for the vast majority of projects, it functions as
- 8:12Speaker 2: a seamless universal translator.
- 8:14Speaker 1: Awesome. Okay, so it translates device to Unicode. But beautiful
- 8:18Speaker 1: Soup itself doesn't actually do the heavy lifting of breaking
- 8:21Speaker 1: down the HTML tags right correct.
- 8:23Speaker 2: It relies on an underlying parser engine. Beautiful Soup is
- 8:26Speaker 2: essentially an interface. It sits on top of different parser engines,
- 8:30Speaker 2: allowing you to swap them out depending on whether your
- 8:32Speaker 2: priority is you know, speed or flexibility.
- 8:35Speaker 1: I know Python comes with the built in HTML parser.
- 8:38Speaker 1: Is that one any good?
- 8:39Speaker 2: It's decent for simple scripts, but if we are building
- 8:42Speaker 2: a professional pipeline, you need something better.
- 8:45Speaker 1: What are the serious alternatives? Then?
- 8:47Speaker 2: You generally look at two main options. The first is
- 8:50Speaker 2: HTML five lib.
- 8:51Speaker 1: Okay, what's special about that one.
- 8:52Speaker 2: This engine parses HTML exactly the same way a modern
- 8:56Speaker 2: web browser would. It is incredibly.
- 8:58Speaker 1: Forgiving, meaning if the HTML is.
- 9:01Speaker 2: Broken exactly, if a webpage has terribly broken HTML, like
- 9:05Speaker 2: missing closing tags, overlapping elements HTML five, lib will actually
- 9:10Speaker 2: syntactically repair it and build a valid tree.
- 9:12Speaker 1: Oh that's really cool.
- 9:13Speaker 2: But there's a downside, right Yeah, it's written in pure Python,
- 9:16Speaker 2: making it quite.
- 9:16Speaker 1: Slow, which completely defeats the purpose of moving away from
- 9:20Speaker 1: seeing eme slowness in the first place. We want raw
- 9:22Speaker 1: speed here, right.
- 9:24Speaker 2: Which points us to the absolute industry standard for this workflow,
- 9:28Speaker 2: the LexML parser ah XML.
- 9:31Speaker 1: Why is it so much faster.
- 9:32Speaker 2: Because it relies on highly optimized SEA libraries under the hood.
- 9:36Speaker 2: Oh nice, Because it executes at sea level speed rather
- 9:39Speaker 2: than being interpreted step by step in Python. It can
- 9:42Speaker 2: parse massive documents and traverse millions of nodes in a
- 9:45Speaker 2: fraction of a second.
- 9:47Speaker 1: The Sea extension advantage. I love that. So we take
- 9:50Speaker 1: our raw HTML, we feed it to beautiful soup, and
- 9:52Speaker 1: the LexML engine just rips through.
- 9:54Speaker 2: It exactly, building this parse tree in our local memory.
- 9:58Speaker 1: Let's dig into the anatomy of that tree for a
- 10:01Speaker 1: developer writing the actual extraction logic. How is this dom
- 10:05Speaker 1: data mapped into Python objects?
- 10:07Speaker 2: Well, the parser maps the entire HTML document into a
- 10:11Speaker 2: tree consisting of four primary Python objects. Okay, four objects, yeah,
- 10:15Speaker 2: and understanding how these objects interact is really the key
- 10:18Speaker 2: to navigating the structure without getting totally lost in the code.
- 10:21Speaker 1: Right, So what's the first one?
- 10:23Speaker 2: The root of this entire structure is the beautiful soup
- 10:25Speaker 2: object itself.
- 10:27Speaker 1: So if we think about tree data structures and computer science,
- 10:30Speaker 1: the beautiful soup object is basically the root node exactly.
- 10:34Speaker 1: It's like the entire filing cabinet containing all the folders.
- 10:37Speaker 2: That's a perfect analogy. It contains the entire state of
- 10:39Speaker 2: the document. And because it is the root representation of
- 10:43Speaker 2: the document as a whole, it doesn't represent any specific
- 10:46Speaker 2: HTML tag.
- 10:47Speaker 1: Oh interesting, So I couldn't query the beautiful soup object
- 10:50Speaker 1: directly for like a class attribute.
- 10:53Speaker 2: No you can't, or in reflink. It has no attributes
- 10:55Speaker 2: of its own. It serves strictly as your starting point
- 10:58Speaker 2: to initiate searches down into the branches.
- 11:00Speaker 1: Gotcha, which leads us to the internal nodes of the tree.
- 11:05Speaker 1: The folders in our filing cabinet, which are the tag objects.
- 11:08Speaker 2: Right When the parser encounters an HTML element, say an
- 11:12Speaker 2: H one header, a DIV container, or a P paragraph,
- 11:15Speaker 2: it wraps that structural element in a tag object.
- 11:18Speaker 1: And this is where the pythonic nature of the library
- 11:21Speaker 1: really shines. I think, oh definitely, because if I have
- 11:23Speaker 1: a tag object assigned to a variable, I get to
- 11:26Speaker 1: type tag dot name to find out what kind of
- 11:28Speaker 1: HTML element it.
- 11:29Speaker 2: Is, or access its attributes dynamically like a Python dictionary
- 11:33Speaker 2: to check its eyed or class.
- 11:36Speaker 1: That's so clean.
- 11:37Speaker 2: You can even modify those tags dynamically, altering the true
- 11:39Speaker 2: structure on the fly if you need to. But the
- 11:42Speaker 2: tag object is just the structural boundary. It tells you
- 11:45Speaker 2: where the data lives, not what the data actually is, which.
- 11:49Speaker 1: Brings us to the actual documents inside the folders.
- 11:51Speaker 2: Exactly when you want the actual human readable text inside
- 11:55Speaker 2: that element, you are looking for the third object type
- 12:00Speaker 2: favigable string.
- 12:01Speaker 1: This is a really crucial distinction for people writing extraction scripts.
- 12:05Speaker 1: The tag and the text inside it are two completely
- 12:08Speaker 1: different objects in memory.
- 12:09Speaker 2: They have to be Think about a complex HTML structure.
- 12:14Speaker 2: You might have a paragraph tag that contains some text,
- 12:16Speaker 2: but it also contains a bold tag which contains more text.
- 12:20Speaker 1: Right, so the tag object defines the nesting exactly.
- 12:23Speaker 2: The navigal string is the leaf node of our tree.
- 12:25Speaker 2: It contains nothing but the pure string literal.
- 12:28Speaker 1: So if I query tagged for its text, beautiful soup
- 12:31Speaker 1: is actually like traversing down to the leaf nose, stripping
- 12:33Speaker 1: away all the structural boundaries and returning just the combined
- 12:36Speaker 1: navigable string data.
- 12:37Speaker 2: Yes, which is exactly why it's so much more reliable
- 12:40Speaker 2: than regular expressions. You navigate parent, child, and sibling relationships natively.
- 12:45Speaker 1: That makes total sense, and that brings us to the
- 12:48Speaker 1: fourth and final object, which you mentioned earlier. Is a
- 12:50Speaker 1: bit of an edge case, yeah, but highly relevant for dynamic.
- 12:53Speaker 2: Sites, right, the common object.
- 12:55Speaker 1: Now, why do we care about developer comments in the
- 12:58Speaker 1: source code? Isn't that just leftover notes like update the
- 13:02Speaker 1: CSS later or something?
- 13:04Speaker 2: Sometimes? Yes, But in modern web development, frontend frameworks often
- 13:08Speaker 2: use HTML comments to temporarily hide dynamic data or raw
- 13:13Speaker 2: Jason payloads. Oh wait really yeah, they hide it there
- 13:16Speaker 2: before it's officially injected into the active dom.
- 13:18Speaker 1: That's fascinating.
- 13:20Speaker 2: So by treating comments as a specialized type of navigable string,
- 13:24Speaker 2: beautiful Soup allows you to easily search for and extract
- 13:27Speaker 2: that hidden application state.
- 13:29Speaker 1: It's incredible how much structure is hiding behind what looks
- 13:32Speaker 1: like a totally chaotic wall of code.
- 13:34Speaker 2: It really is.
- 13:35Speaker 1: So we have the beautiful Soup root, the tag branches,
- 13:38Speaker 1: the naviglobal string leaves, and the comment hidden leaves.
- 13:41Speaker 2: And once you understand that memory structure, writing the extraction
- 13:44Speaker 2: logic becomes almost trivial. You're just traversing a well organized
- 13:48Speaker 2: Python data structure.
- 13:50Speaker 1: Okay, let's bring this all together. We establish the bottleneck
- 13:53Speaker 1: of Selenium, right. Yeah, it's brilliant at rendering JavaScript and
- 13:57Speaker 1: navigating dynamic state, but agonizingly slow at extracting data because
- 14:02Speaker 1: of that HTTP serialization tax.
- 14:04Speaker 2: Correct.
- 14:05Speaker 1: Then we explored beautiful Soup backed by a C level
- 14:09Speaker 1: LXML parser. It can traverse millions of local nodes in milliseconds,
- 14:14Speaker 1: but it can't run JavaScript exactly. So how do we
- 14:17Speaker 1: build a bridge between them? What's the workflow?
- 14:19Speaker 2: The architectural solution is to strictly separate the state generation
- 14:22Speaker 2: phase from the data extraction phase. You do not force
- 14:26Speaker 2: one tool to do both.
- 14:27Speaker 1: Okay, so step one of this transition strategy is state
- 14:29Speaker 1: generation we use Selenium as our navigator. We boot up
- 14:33Speaker 1: the webdriver, navigate to the target URL, and let the
- 14:35Speaker 1: real browser engine execute the initial JavaScript.
- 14:38Speaker 2: You let the browser do what it does best. You
- 14:40Speaker 2: write Selenium commands to interact with the page, injecting authentication tokens,
- 14:44Speaker 2: clicking through drop down venues, scrolling to trigger lazy loaded images.
- 14:48Speaker 1: Basically just manipulating the application until the specific dynamic data
- 14:52Speaker 1: you want is visually rendered on the screen.
- 14:55Speaker 2: Yes, the DOM is now fully updated in the browser's memory.
- 14:59Speaker 2: The data is there, and here is the pivot.
- 15:02Speaker 1: Okay, the pivot.
- 15:02Speaker 2: We completely stop using Selenium's element location methods. We don't
- 15:06Speaker 2: ask it to read the data row by row.
- 15:08Speaker 1: Because that would trigger all those HTTT requests exactly.
- 15:12Speaker 2: Instead, we ask it to dump the memory.
- 15:14Speaker 1: How do we do that?
- 15:15Speaker 2: You call the page source property on your Selenium driver. Okay,
- 15:19Speaker 2: this is the master stroke of this architecture. Instead of
- 15:22Speaker 2: making thousands of network requests to read individual tags, this
- 15:26Speaker 2: executes a single request over the webdriver protocol.
- 15:29Speaker 1: Oh wow.
- 15:30Speaker 2: It asks the browser to serialize the entire fully rendered
- 15:34Speaker 2: DOM state as one massive HTML string and send it
- 15:38Speaker 2: back to your Python script.
- 15:39Speaker 1: So we pay that heavy network communication tax exactly. Once
- 15:43Speaker 1: we literally just grab the entire encyclopedia and bring it out.
- 15:46Speaker 2: Yes, once that raw HTML string is in your local
- 15:49Speaker 2: Python memory, Selenium's job is done. You can minimize the
- 15:53Speaker 2: browser or close it.
- 15:54Speaker 1: Entirely amend we hand it off.
- 15:56Speaker 2: Yep. You take that massive string and pass it directly
- 15:59Speaker 2: into the beautiful soup constructor, making sure to specify the
- 16:02Speaker 2: LXML parser.
- 16:04Speaker 1: And instantly we shift from network bound execution to CPU
- 16:08Speaker 1: bound execution. The C engine rips through the HTML builds,
- 16:12Speaker 1: our root object, our tags, and our navigable strings.
- 16:15Speaker 2: From that point forward, all your iteration, all your searching
- 16:18Speaker 2: for specific classes IDs where text patterns happens locally, so.
- 16:22Speaker 1: You extract your data points instantly bypassing the HTTP overhead entirely.
- 16:27Speaker 1: That's a surprisingly clean workaround. You know. You let the
- 16:31Speaker 1: heavy armoured tool handle the complex environment navigation and you
- 16:35Speaker 1: let the highly optimized parser handle the data traversal.
- 16:38Speaker 2: It really highlights the difference between just knowing how a
- 16:41Speaker 2: library works and knowing how to architect a scalable system totally.
- 16:45Speaker 2: It is the defining design pattern for professional webscraping pipelines.
- 16:49Speaker 2: The next time you're building an extraction tool. Remember to
- 16:52Speaker 2: separate your concerns. State generation belongs to the browser automation tool,
- 16:57Speaker 2: data extraction belongs to the local parser.
- 16:59Speaker 1: That is fantastic advice. Well, before we wrap up, we
- 17:02Speaker 1: want to leave you with a quick review exercise to
- 17:04Speaker 1: test your own understanding of this architecture.
- 17:06Speaker 2: Yeah, so, think back to the bottleneck we diagnosed at
- 17:09Speaker 2: the start of our deep dive. Why do we extract
- 17:12Speaker 2: the full page source to pass to beautiful soup instead
- 17:15Speaker 2: of just querying individual tags through Selenium? Good question, And
- 17:20Speaker 2: what specific protocol mechanism is responsible for Selenium's data extraction bottleneck.
- 17:25Speaker 1: I'll give you a second to think about that. If
- 17:27Speaker 1: you immediately thought about avoiding the thousands of serialization trips
- 17:31Speaker 1: over the jason Wire protocol by grabbing the memory in
- 17:34Speaker 1: one go, well your head is in the exact right place.
- 17:37Speaker 1: Spot on. Here's a final thought to mull over. As
- 17:39Speaker 1: you close out this deep dive, will you realize that
- 17:42Speaker 1: you can write a few lines of Python to programmatically
- 17:44Speaker 1: control a browser trigger any dynamic state, instantly dump the
- 17:49Speaker 1: raw HTML, and traverse it locally at sea level speeds?
- 17:52Speaker 2: It really changes your perspective.
- 17:54Speaker 1: It does you realize the Web isn't just a collection
- 17:57Speaker 1: of pages to visit. It is a massive, globally distributed,
- 18:00Speaker 1: queriable database just waiting for your instructions. The only question
- 18:04Speaker 1: left is what will you extract first