Skip to playerSkip to main content
  • 19 hours ago
Learn how to inspect a web page and identify the HTML elements you’ll need for a Python web scraping project. This beginner-friendly tutorial explains the basic structure of HTML, including tags, text, links, and the relationship between the head and body sections.

Using a practice website, you’ll explore browser developer tools and see how selecting a page element reveals its place in the HTML. Follow examples with table rows, cells, classes, and team names to understand how web page data can be located before scraping it. A practical introduction to HTML inspection, web development tools, and Python web scraping for beginners who want to find specific website data and prepare for extracting it into a CSV.

Category

📚
Learning
Transcript
00:00What's going on, everybody?
00:01Welcome back to another video.
00:02Today, we're gonna be starting
00:03our Python web scraping tutorial series.
00:06Now, this is more of a continuation
00:07of the Python tutorial series,
00:09but because we're gonna be focusing on web scraping
00:11for three or four videos,
00:12I wanted to just make it its own little mini-series.
00:15In this series, I'm gonna show you the basics
00:16of web scraping, how to actually look at HTML,
00:19how to inspect a webpage, how to pull that data in,
00:22and then even put it into a CSV file
00:23so you can save it and use it.
00:25Now, in this series, we're just covering the basics,
00:27which is a fantastic place to start,
00:28but in future series, I'll be going into some
00:30of the more advanced web scraping topics as well.
00:33So without further ado, let's jump on my screen
00:34and get started with web scraping.
00:36Now, the first thing that we need to learn is HTML.
00:38HTML stands for Hypertext Markup Language,
00:41and it's used to describe all of the elements on a webpage.
00:46Now, when we actually go to a website
00:47and start pulling data and information,
00:49we need to know HTML so we can specify exactly
00:52what we want to take off of that website.
00:54So that's where HTML comes in,
00:56and we're gonna look at the basics,
00:57understanding just the basic structure of HTML.
01:00Then we'll go look at a real website,
01:01and you'll kind of see that it's a little bit more difficult
01:04than what we just have right here,
01:05but this is the basic building blocks
01:08to get to what the HTML actually looks like on a website.
01:11Now, this is basically what HTML looks like.
01:15We have these angle brackets with things like HTML,
01:18head, title, body, and then you'll notice
01:21that at the end, we'll have a body,
01:24and then we'll have a body at the bottom.
01:26This forward slash body denotes that this is the end
01:29of the body section in HTML.
01:32So everything inside of this is within this body,
01:36and so there is this hierarchy within HTML.
01:39We have HTML and HTML at the bottom,
01:41which encapsulates all the HTML on the website.
01:44Then we have things like head and head, body and body.
01:48Now, within these sections, we usually have things like classes, tags,
01:51attributes, text, and all these other things,
01:53things that we'll get to in different lessons,
01:55but one of the easiest ones to notice and look at are tags,
02:00things like a P tag or a title tag.
02:02Now, within these tags, because this is a super simple example,
02:06we have these strings here, my first web page,
02:09and this is what's called a variable string,
02:11and this is actual text that we could take out
02:13of this web page.
02:15Now that you understand the super basics of HTML,
02:17let's actually go to our website,
02:19and I'm going to have a link down below,
02:21but it's going to be this one right here.
02:22This is basically just a website that you can,
02:25you know, practice web scraping on.
02:26It's called ScrapeThisSite.com.
02:29And what we're going to do is look at the HTML behind this web page,
02:32and you can do this on any website that you go on.
02:35So we're going to right click.
02:36We're going to go down to inspect.
02:40Now, right off the bat, this looks a lot more complicated
02:43and a lot more complex than the very simple illustration
02:47that we're looking at, but let's kind of roll this up
02:50just a little bit.
02:51You'll notice we have HTML and HTML at the bottom.
02:54We have a head and there is the end of the head
02:56and then a body and the end of the body.
02:59So in a super simple sense, it is similar,
03:02but just the information that's within it
03:04is a lot more difficult.
03:06Now, if we look at this title right here,
03:08this is our title tag.
03:09If we click this little arrow, this is our dropdown.
03:13You'll notice that here we have this string hockey teams,
03:16forms, searching, and pagination.
03:18Now, let's say we didn't know.
03:21We didn't want to click on that and go find it.
03:23There is something that's super helpful
03:24within this inspection page that you can click on right here.
03:27It says select an element in the page to inspect it.
03:30So we're going to click on that.
03:32And as we go through our page and let's click on this title,
03:35it's going to take us to exactly where this is in our HTML.
03:39This is extremely helpful, extremely useful.
03:42For example, let's say the data I want is down here.
03:45I want to take in the Boston Bruins.
03:47I can click on it and it's going to take me to where
03:49that is exactly in the HTML.
03:52This is where we can start writing our web scraping script
03:54to specify, okay, I'm looking for a TR tag.
03:57I'm looking for a TD tag.
03:58I'm looking for the class called team.
04:00This is all information and things that we can use
04:03to specify exactly what we want to pull out of our webpage.
04:07Now, there are other things that we didn't really look at
04:09as well in just our simple illustration.
04:12Let's come right over here.
04:14There's things like hrefs.
04:16Now, these are hyperlinks.
04:18So if we went and then clicked on this,
04:20this is just regular text, but inside of it is this hyperlink,
04:23where if we clicked on it, it would take us to another website.
04:26And typically that's denoted by this href right here.
04:29Then you'll typically see things like a P tag,
04:32which usually stands for a paragraph.
04:34Now, the last thing that I want to show you while we're here,
04:36and we're gonna learn a lot more in the next several lessons.
04:39But if we come right down here,
04:41there is this actual entire table here.
04:43And let's try to find this table.
04:45And I'm having trouble selecting the entire thing,
04:47but let's select this team name.
04:49And if we look at this team name,
04:50you can see that this is encapsulating the table.
04:53So this table tag.
04:54Now, these are super helpful
04:55because it takes in the entire table.
04:57Now, if we wrap this up and we look just at this,
05:00it says class table.
05:02And then we have the end of this table tag.
05:04Now, when we open it, it's gonna have all of this information.
05:08So as you can see, as I'm highlighting over it,
05:10we have these th tags, then we have these td tags,
05:14and even these tr tags, which is the individual data.
05:18And this is something that we'll look at
05:20when we're actually scraping all of the data
05:22from this table in a future lesson.
05:24So this is how we can use HTML,
05:26how we can inspect the webpage
05:27and see exactly what's going on kind of under the hood.
05:30And then in future lessons,
05:31we'll see how we can use this HTML to specify exactly
05:34what data we want to pull out.
05:36Thank you guys so much for watching.
05:37If you liked this video,
05:38be sure to like and subscribe below.
05:40I will see you in the next lesson.

Recommended