How CSS Selectors Work
CSS selectors use the same syntax as CSS stylesheets to identify HTML elements. When you apply a CSS selector as a filter, changedetection.io extracts only the matching elements and monitors them for changes. Key Benefits:- Familiar syntax if you know CSS
- Visual selector tool available in browser mode
- Multiple selectors can be combined
- Works with any HTML content
Basic Selector Syntax
Element Selectors
<p> (paragraph) elements.
ID Selectors
id="price".
Class Selectors
class="product-title".
Attribute Selectors
data-price attribute.
href contains “product”.
Practical Examples
Monitor Product Prices
Monitor Multiple Elements
- Separate Lines
- Combined Selector
You can monitor multiple elements by entering each selector on a new line:Each matching element will appear on a separate line in the output.
Extract Specific Table Data
Monitor Article Headlines
Combining Multiple Filters
You can use multiple CSS selectors together to create powerful filters:Example: E-commerce Product Monitoring
Example: E-commerce Product Monitoring
- Product name (by class)
- Product price (by ID)
- Stock status (by data attribute)
- Review summary (by class)
Example: News Article Tracking
Example: News Article Tracking
Advanced Techniques
Pseudo-selectors
Child and Descendant Selectors
<p> elements).
<p> within the container).
Combining Selectors
Removing Unwanted Elements
Use the “Remove elements” field to exclude parts of the selected content:Testing CSS Selectors
Using Browser DevTools
- Right-click on the element you want to monitor
- Select “Inspect” or “Inspect Element”
- In the DevTools console, test your selector:
- Verify it returns the elements you expect
Using the Visual Selector
When using browser-based fetching (Playwright/WebDriver):- Navigate to the Visual Selector tab in your watch settings
- Click on elements directly on the page
- The CSS selector is automatically generated
- Preview the extracted content in real-time
Common Patterns
Pattern: Monitor Specific Divs
Pattern: Track List Items
Pattern: Monitor Data Attributes
Pattern: Extract Meta Information
Common Pitfalls
When to Use CSS Selectors
Good for:
- Monitoring specific sections of HTML pages
- Tracking product prices and availability
- Following article content changes
- Extracting structured HTML content
- When you need a visual selector tool
Not ideal for:
- JSON APIs (use JSON filtering instead)
- Complex XML documents (consider XPath)
- PDF files (see PDF monitoring)
- When you need advanced conditional logic (use XPath)
CSS vs XPath
| Feature | CSS Selectors | XPath |
|---|---|---|
| Syntax | Familiar to web developers | More powerful but complex |
| Visual selector | ✅ Available | ❌ Not available |
| Text extraction | Element-based | Can extract text nodes directly |
| Conditional logic | Limited | Advanced (contains, not, etc.) |
| Parent selection | ❌ Not possible | ✅ Can select parents |
| Best for | HTML content | XML, RSS, complex queries |
Debugging Tips
Check What’s Being Extracted
- Run a check on your watch
- View the Preview tab to see extracted content
- Adjust your selector if needed
- Run another check to verify
Selector Returns Nothing
- Verify the element exists on the page
- Check if the page requires JavaScript (switch to browser-based fetching)
- Ensure the class/ID names are correct (they may have changed)
- Try a less specific selector
Extracting Too Much Content
- Make your selector more specific
- Add class or ID constraints
- Use child selectors (
>) instead of descendant selectors - Use the “Remove elements” filter to exclude unwanted parts
Real-World Examples
Example: Monitor Reddit Post Title
Example: Monitor Reddit Post Title
Example: Track GitHub Stars
Example: Track GitHub Stars
Example: Follow Tweet Content
Example: Follow Tweet Content
Example: Monitor Job Listings
Example: Monitor Job Listings
Related Topics
- XPath Selectors - More powerful alternative for complex scenarios
- JSON Filtering - Extract data from JSON APIs
- Testing and Debugging - Best practices for testing selectors