Latest / CyberCode Academy / Course 40 - Web Scraping with Python | Episode 20: XPath Fundamentals and Advanced Beautiful Soup Searching
Transcript
- 0:00Speaker 1: So underneath the visual surface of well basically every beautifully
- 0:03Speaker 1: designed web page you visited today, there lies this massive,
- 0:07Speaker 1: invisible tree of data. I mean, it's essentially a labyrinth
- 0:10Speaker 1: of code. You're looking at nicely formatted text, you know,
- 0:13Speaker 1: grids of images, interactive buttons, but what your browser is
- 0:16Speaker 1: actually rendering is a document object model or DOM. And
- 0:21Speaker 1: today we are taking a deep dive right into that labyrinth.
- 0:25Speaker 2: Oh yeah, it really is labyrinth, right.
- 0:26Speaker 1: And we're looking at the architecture of the web, mostly
- 0:29Speaker 1: HTML and XML, and we're going to break down the
- 0:31Speaker 1: specific programmatic tools you actually use to extract data from it.
- 0:35Speaker 1: So think parsing engines, XPath, beautiful soup, LexML. The mission
- 0:40Speaker 1: here is pretty simple. How do we navigate this incredibly
- 0:43Speaker 1: messy architecture and pull out exactly what we need without
- 0:46Speaker 1: you know, getting bogged down and computationally expensive loops or
- 0:50Speaker 1: those superfragile regular expressions.
- 0:52Speaker 2: Yeah, because the modern web is well, it's essentially an
- 0:56Speaker 2: ocean of unstructured or maybe semi structured data. We are
- 1:00Speaker 2: way past the era of manual data collection.
- 1:02Speaker 1: Yeah. Absolutely.
- 1:03Speaker 2: If you're building a competitive intelligence dashboard or feeding a
- 1:07Speaker 2: machine learning model or automating thread intelligence gathering. You have
- 1:12Speaker 2: to be able to programmatically traverse these document trees. But
- 1:17Speaker 2: before we even get to the extraction tools, we have
- 1:19Speaker 2: to talk about the raw material itself.
- 1:21Speaker 1: The actual code we're parsing.
- 1:23Speaker 2: Exactly, specifically the architectural differences between HTML and XML, because
- 1:28Speaker 2: you know, they might look similar structurally, but they're built
- 1:31Speaker 2: for entirely different purposes. Yeah, and that totally dictates how
- 1:34Speaker 2: we parse them.
- 1:35Speaker 1: Okay, let's unpack this. Because HTML's primary job is presentation, right.
- 1:40Speaker 1: It just tells a browser how to render visual elements,
- 1:43Speaker 1: and because of that, it is notoriously forgiving. Like if
- 1:46Speaker 1: a front end developer forgets to close a divtag or
- 1:50Speaker 1: nests a block level element incorrectly modern browser engines like
- 1:54Speaker 1: Blink or WebKit, they'll basically just guess what the developer meant.
- 1:58Speaker 2: Yeah, they just silently fix the dawn behind this and
- 2:00Speaker 2: render the page anyway, right.
- 2:02Speaker 1: Which is great for the user experience, but it is
- 2:04Speaker 1: an absolute nightmare for developers who are trying to write
- 2:07Speaker 1: consistent scraping scripts.
- 2:09Speaker 2: Oh totally. The browser's rendering engine acts as this like
- 2:12Speaker 2: really generous interpreter. You can feed a completely chaotic, broken markup,
- 2:17Speaker 2: and it'll just massage it into a functional tree structure
- 2:19Speaker 2: for you. It's too nice, it is, and it creates
- 2:21Speaker 2: a false sense of security because when you pull the
- 2:24Speaker 2: raw HTML source code via HTTP request directly into your
- 2:27Speaker 2: Python script, you are getting the uncorrected, messy raw string
- 2:32Speaker 2: production grade. HTML is well, it's rarely clean. It's usually
- 2:36Speaker 2: heavily obfuscated by modern JavaScript frameworks that generate you know,
- 2:41Speaker 2: dynamically injected classes and arbitrary layouts.
- 2:44Speaker 1: Which is a stark contrast to XML. I like to
- 2:47Speaker 1: think of it this way. If HTML is this chaotic
- 2:49Speaker 1: forgiving artists, who says close enough when there's a mistake,
- 2:52Speaker 1: XML is the strict accountant, where every single penny has
- 2:55Speaker 1: to balance perfectly.
- 2:56Speaker 2: That is a perfect analogy. Actually, XML isn't meant for
- 2:59Speaker 2: visual display at all. It's a data serialization format.
- 3:02Speaker 1: The rules are absolute, right because it's meant to transfer data.
- 3:06Speaker 2: Exactly, usually between disparate back end systems. So the tags
- 3:10Speaker 2: are completely user defined based on whatever schema you need.
- 3:13Speaker 2: If you're storing customer data, you just define a customer tag,
- 3:16Speaker 2: a name tag, an age tag. It's incredibly human readable.
- 3:20Speaker 2: But that clarity comes with a super rigid constraint. It
- 3:24Speaker 2: must be perfectly well formed. No missing tags, absolutely none
- 3:28Speaker 2: a single missing closing tag or just one improperly nested element,
- 3:33Speaker 2: and a standard XML parser will throw a fatal error.
- 3:36Speaker 2: It halts execution entirely. It will not try to guess
- 3:39Speaker 2: what you meant.
- 3:40Speaker 1: Wow, Okay, but wait, I mean, if they are so
- 3:42Speaker 1: completely different in strictness and purpose, why do we group
- 3:44Speaker 1: them together when we're talking about parsing data.
- 3:46Speaker 2: Ah? Well, what's fascinating here is that, despite the massive
- 3:49Speaker 2: difference in fault tolerance, they actually share a fundamental architecture.
- 3:54Speaker 2: They both resolve into a hierarchical tree structure.
- 3:56Speaker 1: Oh right, the tree.
- 3:58Speaker 2: Yeah, you have a root document which branches into parent nodes,
- 4:01Speaker 2: and those branch into child nodes, and it's all exactly ordered.
- 4:04Speaker 2: And that inherent hierarchy is the key to this whole operation.
- 4:08Speaker 2: Because they both map into a NOE tree, we don't
- 4:10Speaker 2: have to invent completely different traversal paradigms for them.
- 4:13Speaker 1: We can use the same map exactly.
- 4:15Speaker 2: We can use a standardized query language to map the
- 4:18Speaker 2: coordinates of any piece of data. And that is where
- 4:20Speaker 2: XPath comes in.
- 4:21Speaker 1: Oh man, x path. When I'm writing an extraction script,
- 4:24Speaker 1: I immediately reach for XPath just to avoid writing horrific
- 4:28Speaker 1: nested loops because I mean, if you try to parse
- 4:32Speaker 1: a dom tree natively in Python, by writing a loop
- 4:35Speaker 1: that checks every single child of every single parent.
- 4:38Speaker 2: You end up with hundreds of lines of brittle.
- 4:40Speaker 1: Code, unmintainable code. It's awful. But XPath just abstracts all
- 4:44Speaker 1: of that away by giving us a declarative syntax.
- 4:47Speaker 2: Yeah. Instead of writing imperative code that tells the compiler
- 4:50Speaker 2: like exactly how to search the tree step by step,
- 4:53Speaker 2: XPath allows you to simply declare what you are looking for.
- 4:56Speaker 2: You're basically just passing an address. The syntax is super
- 4:59Speaker 2: intuitive because it standard path notation.
- 5:01Speaker 1: Right, it looks a lot like navigating a Unix directory
- 5:03Speaker 1: structure exactly.
- 5:05Speaker 2: You use forward slashes to move up to parents, down
- 5:07Speaker 2: to children, or you could even move laterally to sibling nodes.
- 5:11Speaker 1: Wait. So for the listener, if we already have standard
- 5:14Speaker 1: programming languages like Python, why do we need this entirely
- 5:18Speaker 1: separate x path language just to move up and down
- 5:21Speaker 1: a tree? Like? Why really avoid normal loops?
- 5:24Speaker 2: Because x path handles graft traversal natively at a much
- 5:28Speaker 2: lower level. You can specify a starting node, tell it
- 5:31Speaker 2: to go down three levels, look for a sibling node
- 5:33Speaker 2: that has a specific attribute, and extract the text. The
- 5:37Speaker 2: XPath engine handles all that complex algorithmic routing under the
- 5:41Speaker 2: hood instantly.
- 5:42Speaker 1: Ah right, so it just wildly more efficient.
- 5:44Speaker 2: Yeah, and it becomes incredibly powerful when you introduce predicates.
- 5:47Speaker 1: Hedicuitts are basically the filters right right.
- 5:49Speaker 2: Filter conditions applied directly within the path. So instead of say,
- 5:53Speaker 2: retrieving an array of all the table rows and then
- 5:55Speaker 2: writing a Python script to filter them later, you write
- 5:58Speaker 2: an XPath query that says retrieve only the table rows
- 6:02Speaker 2: where the third column contains a specific number. The query
- 6:05Speaker 2: executes against the parse tree in memory and hands you
- 6:08Speaker 2: only the highly refined nose you actually care about.
- 6:11Speaker 1: That is so clean, But that brings up a critical bottleneck. Actually,
- 6:16Speaker 1: XPath is the map, but we still need an engine
- 6:19Speaker 1: to actually read that raw string of HTML or XML
- 6:22Speaker 1: and build that navigable tree in our system's memory in
- 6:25Speaker 1: the first place.
- 6:25Speaker 2: Yes, the parser itself right.
- 6:27Speaker 1: And in Python, our primary toolkit for this is beautiful
- 6:30Speaker 1: soup paired with the LexML parser. Now you could use
- 6:33Speaker 1: Python's built in HDL parser, but I mean performance wise,
- 6:37Speaker 1: it usually falls really sure on large scale scraping operations.
- 6:40Speaker 2: So diffinitely. The bottleneck with native Python parsers is always
- 6:43Speaker 2: execution speed and memory management. XML is actually a binding
- 6:47Speaker 2: for SEA libraries.
- 6:48Speaker 1: Oh wow, so it's running.
- 6:49Speaker 2: In C YEP Because the heavy lifting of parsing that
- 6:52Speaker 2: string into a node tree is handled at the SEA level.
- 6:55Speaker 2: It largely bypasses Python's Global interpreter lock or GIL, so
- 7:00Speaker 2: it is blisteringly fast, and crucially, LXML is robust enough
- 7:05Speaker 2: to process perfectly formed XML, but it's also flexible enough
- 7:09Speaker 2: to aggressively correct and parse that messy broken HTML tag soup.
- 7:14Speaker 1: We talked about, So it's the best of both worlds.
- 7:16Speaker 1: We initialize our beautiful soup object, feed it the raw
- 7:19Speaker 1: HTML string we fetched specify XML as the engine, and boom,
- 7:24Speaker 1: the CA library builds the dom tree in memory. Now
- 7:26Speaker 1: we can actually start searching exactly. Let's do an audio
- 7:29Speaker 1: walk through for the listener to picture this. Imagine a
- 7:32Speaker 1: simple HTML file right, Let's say it's called Tom and Jerry.
- 7:35Speaker 1: You have the root node a title that says the
- 7:37Speaker 1: story of Tom and Jerry, and inside the body you
- 7:39Speaker 1: have images and anchor tags, which are.
- 7:41Speaker 2: Links right a standard basic structure.
- 7:43Speaker 1: Navigating that requires understanding how beautiful soup search functions manage memory.
- 7:48Speaker 1: The two main ones you use are find and findal.
- 7:51Speaker 1: Find is basically a sniper. It traverses the tree and
- 7:54Speaker 1: returns the very first node that matches your parameters.
- 7:57Speaker 2: Mechanically, what's happening There is an early exit condition, the
- 8:01Speaker 2: millisecond the fine function hits a matching tag, It halts
- 8:04Speaker 2: the search execution entirely and just returns the object.
- 8:07Speaker 1: Which saves vital CPU cycles exactly. But then you have
- 8:11Speaker 1: find all, which is more like casting a massive net.
- 8:13Speaker 1: It forces the parser to traverse the entire document and
- 8:18Speaker 1: map every single matching node into a Python list in memory.
- 8:22Speaker 1: So if you're scraping a deeply nested dom with ten
- 8:24Speaker 1: thousand paragraph tags, find all will allocate memory for all
- 8:29Speaker 1: ten thousand, even if you only want the first three.
- 8:31Speaker 2: Right, and that memory mapping introduces severe latency if you're
- 8:34Speaker 2: scaling this across thousands of pages. To mitigate that overhead,
- 8:38Speaker 2: you use the limit argument within.
- 8:40Speaker 1: Findal ah right, limiting the size of the net.
- 8:43Speaker 2: Exactly if you only the first three links in that
- 8:44Speaker 2: tom and Jerry file. You just pass limit three. The
- 8:47Speaker 2: parser scans the tree, but the moment that array hits
- 8:49Speaker 2: three elements, it stops. It prevents the script from unnecessarily
- 8:53Speaker 2: parsing the rest of the document, keeping your memory footprint
- 8:56Speaker 2: super lightweight.
- 8:57Speaker 1: That's incredibly smart. Okay, let's escalate this with some more
- 9:00Speaker 1: advanced tactics, because real world scraping is well, it's rarely
- 9:04Speaker 1: as simple as just finding a tag and limiting it.
- 9:07Speaker 1: E commerce sites, for example, they are notorious for burying
- 9:10Speaker 1: the data you actually want inside like ten layers of
- 9:13Speaker 1: arbitrary formatting tags.
- 9:15Speaker 2: Oh it's a nightmare. Dives spans inside DIBs right.
- 9:18Speaker 1: And by default, Beautiful Soup searches recursively. It checks a
- 9:22Speaker 1: parent node than the child, than the child's child, drilling
- 9:25Speaker 1: all the way down to the deepest leaf of the
- 9:27Speaker 1: tree before moving to the next branch.
- 9:29Speaker 2: And recursive searching is very thorough, but computationally it's expensive.
- 9:33Speaker 2: Every time the engine steps down a level, it adds
- 9:35Speaker 2: processing overhead. But Beautiful Soup gives you a way to
- 9:38Speaker 2: prune the search tree. You can set the argument recursive false.
- 9:42Speaker 1: Okay, wait, let me play Devil's advocate here. Why would
- 9:45Speaker 1: I ever set recursive false Because if I'm scraping a
- 9:48Speaker 1: massive site, my biggest fear is missing the data like
- 9:51Speaker 1: nested pricing data buried in a span. Are we intentionally
- 9:55Speaker 1: putting blinders on and risking data loss?
- 9:57Speaker 2: Well, if we connect this to the bigger picture, if
- 10:00Speaker 2: you are doing exploratory scraping on an unknown dom, absolutely
- 10:04Speaker 2: keep recursion on. You need to map everything. But consider
- 10:08Speaker 2: a scenario where you're parsing a structured XML feed or
- 10:11Speaker 2: an HTML table where you already know the schema.
- 10:14Speaker 1: Oh so you already know exactly where the data lives.
- 10:16Speaker 2: Right, If you know for a fact that the data
- 10:19Speaker 2: points you need are exactly one structural layer down from
- 10:22Speaker 2: the body tag, running a recursive search is a huge
- 10:25Speaker 2: waste of power. The engine will waste time drilling down
- 10:28Speaker 2: into SVG icon paths and hidden formatting nodes that you
- 10:31Speaker 2: already know are useless.
- 10:32Speaker 1: Got it? So, if I search for an anchor tag
- 10:35Speaker 1: on the top level document with recursive false, it might
- 10:38Speaker 1: return nothing because the links are nested inside the body.
- 10:42Speaker 1: But if I search for a paragraph tag that I
- 10:44Speaker 1: know is a direct child of the body, it grabs
- 10:46Speaker 1: it instantly.
- 10:47Speaker 2: Exactly by setting recursive falls. You are intentionally pruning the
- 10:51Speaker 2: tree to optimize traversal speed. You're basically telling the partser
- 10:55Speaker 2: I know the structure, ignore all the deep noise.
- 10:57Speaker 1: That makes total sense. Okay, let's shift gears to another
- 11:00Speaker 1: massive headache in real world extraction custom attributes. Standard HTML
- 11:06Speaker 1: has expected attributes, right like H referra link or src
- 11:10Speaker 1: for an image.
- 11:10Speaker 2: Yeah, standard stuff.
- 11:11Speaker 1: But developers use custom data attributes all the time now,
- 11:15Speaker 1: especially with JavaScript frontend frameworks. You'll see elements like a
- 11:18Speaker 1: div with data product eyed one, two, three, four, five,
- 11:21Speaker 1: or even something with an underscore like name William Hannah.
- 11:24Speaker 2: And those custom attributes introduce a fundamental keyword collision problem
- 11:28Speaker 2: in Python.
- 11:29Speaker 1: Tell me about it.
- 11:30Speaker 2: Let's say a developer added a custom attribute simply called name,
- 11:33Speaker 2: So the HTML is literally an image tag with name
- 11:36Speaker 2: product shot. If you try to pass name product shot
- 11:39Speaker 2: is a keyword argument into beautiful soups Fine method, the
- 11:42Speaker 2: Python compiler will throw a type error and.
- 11:44Speaker 1: Just crash because name is already a reserved argument within
- 11:47Speaker 1: the fine function itself.
- 11:48Speaker 2: Exactly. The function uses the name parameter to specify which
- 11:51Speaker 2: actual HTML tag you were looking for, like nam div.
- 11:55Speaker 2: So if you pass a custom attribute called name. You
- 11:57Speaker 2: are overwriting the method's internal logic.
- 12:00Speaker 1: It's a total collision. And it gets even worse with hyphens.
- 12:03Speaker 1: Like if you have data product eyed one two three
- 12:06Speaker 1: four five. If you try to pass that as a
- 12:09Speaker 1: keyword argument, python syntax rules completely break down.
- 12:12Speaker 2: Oh yeah, because the Python interpreter evaluates the hyphen as
- 12:15Speaker 2: a mathematical subtraction operator. Right.
- 12:18Speaker 1: It thinks you are literally trying to subtract the variable
- 12:20Speaker 1: product from the variable data.
- 12:22Speaker 2: It's hilarious but incredibly frustrating.
- 12:25Speaker 1: So how do we safely route around the compiler Because
- 12:28Speaker 1: we know the DOM has the data and we know
- 12:30Speaker 1: what the attribute is called.
- 12:31Speaker 2: We use the attress dictionary. Instead of passing the target
- 12:34Speaker 2: attribute as a direct keyword argument. You just pass a
- 12:37Speaker 2: standard Python dictionary to the actress parameter. Uh So, the
- 12:40Speaker 2: dictionary key is a string representing the exact attribute namelike
- 12:44Speaker 2: data product eyed in quotes. Yeah, and the value is
- 12:47Speaker 2: the target string one two three four five. Because the
- 12:50Speaker 2: hyphen is now safely contained within a string literal inside
- 12:54Speaker 2: a dictionary key, the Python interpreter ignores it completely.
- 12:57Speaker 1: And beautiful Soup parses the dom tree flawlessly. That actress
- 13:03Speaker 1: dictionary is basically the ultimate escape patch for whenever back
- 13:06Speaker 1: end data structures clash with Python syntax.
- 13:09Speaker 2: It really is. Yeah, now let's take that a step further.
- 13:12Speaker 2: We've established how to navigate the tree manage memory bypass
- 13:15Speaker 2: intax errors, but ultimately the tag is just the container.
- 13:20Speaker 2: The actual gold we are trying to extract is the
- 13:22Speaker 2: human readable text, the string sitting inside that container.
- 13:26Speaker 1: Right, the actual data.
- 13:28Speaker 2: Searching by string content allows us to reverse engineer are traversal.
- 13:32Speaker 2: So instead of looking for a specific structural container and
- 13:35Speaker 2: hoping the data is inside, we could search the parse
- 13:37Speaker 2: tree directly for exact strings. If you pass a text
- 13:40Speaker 2: argument into your search, beautiful Soup traverses the whole dom
- 13:44Speaker 2: and returns the exact nodes where that specific string appears
- 13:47Speaker 2: as standalone text.
- 13:48Speaker 1: So you could search the Tom and Jerry file for
- 13:50Speaker 1: exactly Tom, and it finds the exact note.
- 13:52Speaker 2: Exactly and a quick shortcut. Actually, if you provide a
- 13:55Speaker 2: set of values in the attribute stctionary but you don't
- 13:57Speaker 2: give it a key, beautiful Soup automatically assumes you are
- 14:00Speaker 2: searching the class attribute.
- 14:01Speaker 1: Oh nice. So if you just search for values starting
- 14:04Speaker 1: with nanny it'll successfully match a paragraph tag with the
- 14:07Speaker 1: class animated Yep.
- 14:08Speaker 2: It's super handy, but you know, exact matching is great,
- 14:11Speaker 2: but real power comes from customized logic.
- 14:15Speaker 1: This is an absolute life saver because I can't tell
- 14:17Speaker 1: you how many times I've had to write these incredibly
- 14:20Speaker 1: fragile regular expressions just to clean up deeply nested text
- 14:24Speaker 1: that's polluted with arbitrary white space, random span tags, injected
- 14:28Speaker 1: line breaks. It's a mess.
- 14:30Speaker 2: Rejects is powerful, but applying it to raw HTML strings
- 14:34Speaker 2: is notoriously error prone because HTML is not a regular language. However,
- 14:39Speaker 2: once the HTML is parsed into a dom tree, beautiful
- 14:42Speaker 2: soup allows you to pass custom Python functions, specifically lamb
- 14:45Speaker 2: to functions, directly into the search methods.
- 14:48Speaker 1: Wait really, this completely changes the paradigm. So instead of
- 14:51Speaker 1: just giving it static search parameters, you're injecting your own
- 14:53Speaker 1: custom logic directly into the traversal engine itself.
- 14:56Speaker 2: Exactly. The parser takes your custom lamb to function and
- 14:59Speaker 2: applies it sequentially to every single node in the tree.
- 15:02Speaker 2: It only returns the nose that evaluate to true based
- 15:05Speaker 2: on whatever logic you wrote. Oh wo, So let's say
- 15:07Speaker 2: you are scraping a forum, and the HTML is incredibly messy.
- 15:12Speaker 2: The text is broken up by random image tags, bowl tags, whatever.
- 15:16Speaker 2: You can write a tiny Python lambda function that evaluates
- 15:19Speaker 2: each node, checks if it's the only string child of
- 15:22Speaker 2: its parent, strips out the white space, and checks if
- 15:25Speaker 2: the length is greater than zero.
- 15:27Speaker 1: And you just completely eliminated the need for complex rejects
- 15:30Speaker 1: post processing. The PARS tree evaluates the logic dynamically and
- 15:34Speaker 1: just hands you back a perfectly clean data set. So
- 15:37Speaker 1: what does this all mean for you, the listener trying
- 15:40Speaker 1: to actually use this.
- 15:41Speaker 2: It means you're no longer just blindly extracting data. You
- 15:44Speaker 2: are compiling a highly structured, perfectly queriable database out of
- 15:49Speaker 2: a completely chaotic string of markup right.
- 15:51Speaker 1: You manage the memory with limits, you prune the tree
- 15:54Speaker 1: with non recursive searching, You bypass the syntax collisions using
- 15:57Speaker 1: the Attris dictionary, and you execute surgical LOKs distraction using
- 16:00Speaker 1: custom lambda functions. It's brilliant.
- 16:02Speaker 2: It's a complete toolkit.
- 16:03Speaker 1: Okay, let's summarize the journey we just took. We started
- 16:07Speaker 1: with the raw materials, understanding the strict, perfectly validated world
- 16:11Speaker 1: of XML versus the visually forgiving chaotic ecosystem of HTML.
- 16:16Speaker 1: Realizing they both compile into a tree structure. We used
- 16:20Speaker 1: XPath as our map to navigate without writing brittle loops.
- 16:23Speaker 1: Then we spun up the LexML parser with beautiful soup
- 16:26Speaker 1: to process those trees at sea level speeds. We managed
- 16:29Speaker 1: our memory by choosing quick early exits with fine and
- 16:32Speaker 1: capped our massive list allocations using limit and findal When
- 16:35Speaker 1: we needed to, we intentionally put on the blinders using
- 16:38Speaker 1: recursive false to skip irrelevant branches. We avoided Python errors
- 16:42Speaker 1: with custom schemas by using the atrus dictionary. And finally
- 16:45Speaker 1: we ditched rejects by injecting Python lambda functions directly into
- 16:48Speaker 1: the search to pull pristine strings out of the mess.
- 16:51Speaker 2: You really covered it all, So before.
- 16:53Speaker 1: We wrap up, I want you, the listener, to run
- 16:56Speaker 1: a quick mental exercise to lock this in. Imagine you
- 16:59Speaker 1: are parsing a heavily obfuscated web page and you realize
- 17:03Speaker 1: the critical data point you need is hidden inside a
- 17:06Speaker 1: custom attribute literally labeled data user token. Knowing what you
- 17:10Speaker 1: now know about hyphens and Python keywords, how would you
- 17:13Speaker 1: structure that search to avoid getting a fatal mathematical subtraction error.
- 17:17Speaker 2: Take a second to think about it.
- 17:19Speaker 1: If you mentally pictured wrapping that hyphenated string inside the
- 17:23Speaker 1: etch dictionary, you got it. You've mastered the syntax workaround.
- 17:27Speaker 2: And you know this raise is a really important question
- 17:29Speaker 2: as we look to the future. We spent this whole
- 17:32Speaker 2: time talking about how to build a robust logic to
- 17:34Speaker 2: handle messy human written HTML. But as artificial intelligence becomes
- 17:39Speaker 2: more prevalent, literally dynamically generating entire domitries on the fly
- 17:43Speaker 2: at lightning speed, how might they hid an architecture of
- 17:46Speaker 2: the web actually change. Oh that's a wild thought, right.
- 17:49Speaker 1: If machines are writing the code specifically for other machines
- 17:52Speaker 1: to ingest, will that fault tolerant, chaotic htmlitree just disappear entirely,
- 17:59Speaker 1: replaced by hyper t deeply nested data structures that actually
- 18:02Speaker 1: mimic XML.
- 18:04Speaker 2: The dom basically rewriting itself to lock out human readability
- 18:07Speaker 2: entirely just to accommodate machines. That is a fascinating architectural
- 18:11Speaker 2: shift to watch out, and that wraps up our technical
- 18:14Speaker 2: deep dive into data parsing and dom tversal. Keep exploring
- 18:17Speaker 2: those invisible structures all around you, and we'll cut you
- 18:19Speaker 2: on the next deep dive.