CSS Selector Mastery
From Zero to Web Scraping Hero - Learn Through Interactive Practice
Current Level
CSS Rookie
Learning Streak
1 Day
Total Points
0/100
CSS Selectors: Your Web Navigation Compass
Memory Hack: "CSS = Choose, Select, Style"
Choose elements on the page
Select them with precision
Style or scrape what you need!
Imagine CSS selectors as a GPS for web pages. Just like you need an address to find a house, you need selectors to find HTML elements. Whether you're styling a website or scraping data, selectors are your roadmap!
Element Selector
p { }
Selects ALL paragraphs
Class Selector
.highlight { }
Selects elements with class="highlight"
ID Selector
#header { }
Selects element with id="header"
Attribute Selector
[href] { }
Selects elements with an href attribute
Sample Web Page Structure:
Welcome to CSS Mastery
This paragraph teaches basic selectors.
This paragraph has a class.
Home LinkQuick Challenge: Selector Matching
Drag the Selectors:
Selects HTML tags directly
Uses dot (.) prefix
Uses hash (#) prefix
Uses square brackets
Element Selectors: The Foundation Stones
Memory Hack: "HTML Tags Are Like People's Names"
Just like calling "John!" in a room gets John's attention, writing div
selects all div elements!
Amazon Product Data Extraction
You need to scrape product information from an online store. The HTML structure shows:
Amazon-style Product Listing:
Business Need: Extract ALL product titles using h3
, ALL descriptions using p
, ALL prices using span
Pro Tip for Web Scraping:
Element selectors are perfect when websites use consistent HTML tags for similar content. Many e-commerce sites use h3
for product names!
Social app Profile Mining
Extract profile information from Social app search results using parent-child relationships:
Scraping Strategy:
h4
- Gets ALL profile namesp
- Gets ALL job titles and companiesspan
- Gets ALL connection counts
Sample E-commerce Product Page:
iPhone 14 Pro Max
128GB, Space Black, Unlocked
$1,099.00MacBook Air M2
13-inch, 8GB RAM, 256GB SSD
$1,199.00AirPods Pro (2nd Gen)
Active Noise Cancellation
$249.00E-commerce Data Challenge
Drag the Selectors:
Get all product names from listings
Get all pricing data
Get product details and specifications
Get navigation and product links
Compound Selectors: The Precision Tools
Memory Hack: "No Space = No Escape"
Compound selectors are written **without a space** and combine multiple conditions on a single element. Perfect for precise targeting!
LinkedIn Post Analytics
Extract only sponsored posts that have high engagement from a LinkedIn feed:
LinkedIn-style Feed Structure:
Target Sponsored Posts
div.post.sponsored
Divs with BOTH "post" and "sponsored" classes
High-Engagement Buttons
button.like.trending
Buttons with BOTH "like" and "trending" classes
Verified User Links
a.profile[data-verified="true"]
Profile links that are verified
App Store Intelligence
Find only premium, top-rated apps that are currently on sale:
Precise Targeting:
.app-card.premium.featured
- Only premium featured appsbutton.download.sale
- Sale download buttons.app-card.free.popular
- Popular free apps
Sample App Store Listings:
App Store Filtering Challenge
Drag the Selectors:
Apps with both "app" and "premium" classes
Buttons with both "download" and "sale" classes
Links with both "developer" and "verified" classes
Apps with both "free" and "popular" classes
Combinators: Navigation Relationship Masters
Memory Hack: "Family Relations in HTML"
Space = All descendants (kids, grandkids, etc.)
> = Direct children only
+ = Next sibling
~ = All following siblings
Reddit/Forum Comment Extraction
Extract only top-level comments vs nested replies in Reddit threads:
Reddit Thread Structure:
Precise Extraction:
.thread > .comment
- Only top-level comments.thread .comment
- ALL comments (including nested).comment + .replies
- Reply sections after comments
Yelp/Google Business Mining
Extract business information with parent-child relationships from directory listings:
Strategic Selectors:
.business-listing > h3
- Direct business names.business-name + .rating
- Ratings after names.contact-info span
- All contact numbers
Sample Business Directory:
Business Directory Challenge
Drag the Selectors:
Only immediate business names in listings
Ratings immediately following business names
All contact details within contact sections
All paragraphs following rating elements
Class Selectors: The Category Masters
Memory Hack: "DOT = Designated Object Type"
Classes group similar elements. Think of school classes - all students in "Math Class" wear the same schedule. The dot (.) finds the class!
Yahoo Finance / Bloomberg Scraping
Extract stock prices, company names, and market movements from financial websites:
Stock Market Dashboard:
Business Intelligence Extraction:
.company-name
- All company names.stock-price
- Current stock prices.price-change.positive
- Only stocks trending up
Financial Data Pro Tip:
Many financial sites use predictable class names: .price
, .ticker
, .market-cap
. Look for these patterns!
Zillow/Realtor.com Property Data
Extract property prices, addresses, and features from real estate websites:
Property Intelligence:
.address
- Property locations.price
- Listing prices.property-card.featured
- Premium listings only
Sample Stock Market Dashboard:
Financial Data Challenge
Drag the Selectors:
Get current trading prices
Only stocks that gained value
Get all company identifiers
Only highlighted stock entries
ID Selectors: The Unique Identifiers
Memory Hack: "HASH = Has A Special Home"
IDs are unique! Like your home address, only ONE element can have a specific ID. The hash (#) symbol finds that special home!
Wikipedia Article Extraction
Extract main content, references, and specific sections from Wikipedia articles:
Wikipedia Article Structure:
Strategic Extraction:
#content
- Main article text#references
- Citation information#toc
- Article structure/headings
GitHub Project Intelligence
Extract repository information, README content, and file structures from GitHub:
Developer Intelligence:
#readme
- Project documentation#repository-details
- Project metrics#file-navigator
- Code structure
Sample GitHub Repository Page:
Awesome Project
This is a revolutionary web scraping tool...
GitHub Intelligence Challenge
Drag the Selectors:
Get README content and description
Get stars, forks, and issue counts
Get file and directory listing
Get project contributor details
Attribute Selectors: The Detail Detectives
Memory Hack: "BRACKETS = Be Ready And Check Key-value Exact Target Selection"
Square brackets [attribute] let you find elements by their properties - like searching for people by their job title!
Business Directory Scraping
Extract contact information from business directories and company websites:
Contact Information Patterns:
Email Links
[href^="mailto:"]
Links starting with "mailto:"
Phone Numbers
[href^="tel:"]
Links starting with "tel:"
External Company Links
[href^="https://"]
External website references
PDF Documents
[href$=".pdf"]
Links ending with ".pdf"
Lead Generation Gold:
Combine these for powerful business intelligence: a[href^="mailto:"]
gives you all email contacts!
Survey and Form Intelligence
Analyze form structures and extract specific input types from registration forms:
Form Intelligence Extraction:
[type="email"]
- Email input fields[required]
- Mandatory form fields[data-required="true"]
- Custom required fields
Sample Business Contact Page:
Contact Mining Challenge
Drag the Selectors:
Get all email contact links
Get all telephone contact links
Get email form inputs
Get all PDF file references
Hierarchy Selectors: The Family Tree Navigators
Memory Hack: "Family Relations in HTML"
Space = All descendants (kids, grandkids, etc.)
> = Direct children only
+ = Next sibling
~ = All following siblings
Website Navigation Intelligence
Extract main navigation vs sub-menu items from complex website headers:
Website Navigation Structure:
Navigation Intelligence:
.main-nav > a
- Only top-level navigation links.main-nav a
- ALL navigation links (including submenus).dropdown > a
- Direct dropdown triggers
Blog/Article Structure Analysis
Extract article sections, related content, and sidebar information from content sites:
Content Structure Mapping:
.main-content > h2
- Main article titles only.main-content p
- All article paragraphsh2 + p
- First paragraph after title
Sample Website Structure:
Content Structure Challenge
Drag the Selectors:
Only direct navigation menu items
Top-level content headings only
Paragraphs immediately after h2 headings
All links within dropdown menus
Pseudo Selectors: The State and Position Masters
Memory Hack: "COLON = Condition Or Location Or Numbers"
Pseudo-selectors use : to target elements by their state, position, or special conditions!
Financial Table Scraping
Extract specific rows from financial reports, pricing tables, or data grids:
Pricing Table Intelligence:
First Plan
tr:first-child
Header row or first pricing tier
Last Plan
tr:last-child
Premium/enterprise tier
Even Rows
tr:nth-child(even)
Alternate row highlighting
Exclude Headers
tr:not(:first-child)
Data rows only, skip headers
Search Result Optimization
Extract specific results from search pages, product listings, or news feeds:
Search Intelligence Patterns:
li:nth-child(-n+3)
- Top 3 search resultsli:nth-last-child(-n+2)
- Last 2 resultsli:nth-child(odd)
- Every other result
Sample Search Results Page:
Search Optimization Challenge
Drag the Selectors:
Most relevant result only
First three search results
All links except the last one
The last button in filter group
Advanced Selectors: The Master's Toolkit
Memory Hack: "COMBINE = Create Outstanding Multi-target Incredible Navigation Experiences"
Mix and match selectors for surgical precision - like a Swiss Army knife for HTML!
Advanced Product Intelligence
Create complex selectors for competitive price monitoring across multiple e-commerce sites:
Social Media Intelligence Gathering
Extract high-engagement content and influencer data from social platforms:
Viral Posts
.post.trending .engagement[data-likes*="k"]
Posts with thousands of likes
Verified Accounts
.profile.verified:not(.private) a[href*="twitter"]
Public verified Twitter profiles
Sponsored Content
.post[data-promoted="true"] .brand-mention:first-child
First brand mention in ads
Sample Advanced E-commerce Site:
Gaming Laptop Pro
Wireless Headphones
Master Challenge: Advanced Selector Construction
Drag the Selectors:
Products on sale that are still in stock
HTTPS links with 'premium' in class name
Engagement data from trending posts
First next link with AJAX functionality