Residential Proxies
Allowlisted 200M+ IPs from real ISP. Managed/obtained proxies via dashboard.
Proxies Services
Residential Proxies
Allowlisted 200M+ IPs from real ISP. Managed/obtained proxies via dashboard.
Residential (Socks5) Proxies
Over 200 million real IPs in 190+ locations,
Unlimited Residential Proxies
Unlimited use of IP and Traffic, AI Intelligent Rotating Residential Proxies
Static Residential proxies
Long-lasting dedicated proxy, non-rotating residential proxy
Dedicated Datacenter Proxies
Use stable, fast, and furious 700K+ datacenter IPs worldwide.
Mobile Proxies
Dive into a 10M+ ethically-sourced mobile lP pool with 160+ locations and 700+ ASNs.
Scrapers
Collection of public structured data from all websites
Proxies
Residential Proxies
Allowlisted 200M+ IPs from real ISP. Managed/obtained proxies via dashboard.
Starts from
$0.77/ GB
Residential (Socks5) Proxies
Over 200 million real IPs in 190+ locations,
Starts from
$0.045/ IP
Unlimited Residential Proxies
Unlimited use of IP and Traffic, AI Intelligent Rotating Residential Proxies
Starts from
$79/ Day
Rotating ISP Proxies
ABCProxy's Rotating ISP Proxies guarantee long session time.
Starts from
$0.77/ GB
Static Residential proxies
Long-lasting dedicated proxy, non-rotating residential proxy
Starts from
$5/MONTH
Dedicated Datacenter Proxies
Use stable, fast, and furious 700K+ datacenter IPs worldwide.
Starts from
$4.5/MONTH
Mobile Proxies
Allowlisted 200M+ IPs from real ISP. Managed/obtained proxies via dashboard.
Starts from
$1.2/ GB
Scrapers
Web Unblocker
Simulate real user behavior to over-come anti-bot detection
Starts from
$1.2/GB
Serp API
Get real-time search engine data With SERP API
Starts from
$0.3/1K results
Video Downloader
Fully automated download of video and audio data.
Starts from
$0.07/GB
Scraping Browser
Scale scraping browsers with built-inunblocking and hosting
Starts from
$2.5/GB
Documentation
All features, parameters, and integration details, backed by code samples in every coding language.
TOOLS
Resources
Addons
ABCProxy Extension for Chrome
Free Chrome proxy manager extension that works with any proxy provider.
ABCProxy Extension for Firefox
Free Firefox proxy manager extension that works with any proxy provider.
Proxy Manager
Manage all proxies using APM interface
Proxy Checker
Free online proxy checker analyzing health, type, and country.
Proxies
AI Developmen
Acquire large-scale multimodal web data for machine learning
Sales & E-commerce
Collect pricing data on every product acrossthe web to get and maintain a competitive advantage
Threat Intelligence
Get real-time data and access multiple geo-locations around the world.
Copyright Infringement Monitoring
Find and gather all the evidence to stop copyright infringements.
Social Media for Marketing
Dominate your industry space on social media with smarter campaigns, anticipate the next big trends
Travel Fare Aggregation
Get real-time data and access multiple geo-locations around the world.
By Use Case
English
繁體中文
Русский
Indonesia
Português
Español
بالعربية
This article systematically explains the core principles and practical applications of the contains(@class, 'value') selector in XPath, covering key scenarios such as dynamic class name processing, multiple class name matching, performance optimization, and provides solutions to deal with the complex class name structure of modern Web frameworks.
The technical principle and grammatical structure of the class contains selector
Basic grammar analysis
The XPath contains() function is used to detect whether an attribute value contains a specific substring. Its core syntax is:
//tagname[contains(@class, 'partial-class-name')]
For example, //div[contains(@class, 'menu')] matches all div elements whose class attribute contains "menu", such as class="main-menu" or class="menu-item".
Comparison with exact match
Exact match: @class='target' requires the attribute value to be exactly equal to "target" and cannot handle scenarios with multiple class names or dynamic prefixes;
Contains matching: contains(@class, 'target') matches class names that contain the substring anywhere, which is suitable for dynamic classes in frameworks such as Bootstrap (such as col-md-6).
Handling the priority of multiple class names
When an element contains multiple class names (such as class="btn btn-primary active"), you can filter it through chained contains:
//button[contains(@class, 'btn') and contains(@class, 'active')]
Core application scenarios and practical cases
Dynamic class name matching
Modern web frameworks (such as React and Vue) often generate random hash class names (such as _1a2b3c), but retain some fixed semantic prefixes. For example:
//div[contains(@class, 'product-card_')] // matches the class name product-card_1a2b generated by Next.js
Responsive layout positioning
Bootstrap's grid system class names (such as col-md-6, col-lg-4) can be used to achieve cross-device positioning through partial matching:
//div[contains(@class, 'col-')] // Select all grid column elements
Status Tracking
For dynamic state changes (such as activated state, disabled state), capture elements by changing the class name:
//li[contains(@class, 'active')]/a // Get the currently activated navigation link
Compound selector optimization
Combine with other attributes to achieve precise positioning, for example, match elements with the "modal" class and a data-testid attribute:
//div[contains(@class, 'modal') and @data-testid='login-form']
Common Problems and Performance Optimization Strategies
Partial match conflict
When the substring appears in a non-target class name (such as class="btn confirmation" matches contains(@class, 'on')), the solution is:
Increase positioning accuracy: Narrow the scope by combining hierarchical relationships or adjacent elements
//form[@id='signup']//button[contains(@class, 'btn')]
Use regular expressions (XPath 2.0+ is required, and some browsers are not compatible):
//*[matches(@class, '\bprimary-button\b')]
Performance bottlenecks and solutions
The full document scanning feature of contains() may lead to inefficient execution. Optimization strategies include:
Hierarchical limitation: Narrow the search scope by parent node first
//ul[@id='main-nav']//li[contains(@class, 'dropdown')]
Index acceleration: Direct positioning using position index (applicable to fixed structures)
(//div[contains(@class, 'card')])[1] // Select the first matching element
Dynamic page compatibility
Dealing with asynchronous loading issues of SPA (single page application):
Explicit waits: Configuring dynamic wait conditions in tools like Selenium
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//div[contains(@class, 'loader')]"))
)
Incremental matching: Dynamically generate XPath based on the changing characteristics of the class name (such as the timestamp suffix loading_1623984000)
Advanced Technique: Combine with other XPath functions to enhance location capabilities
1 Combining starts-with and ends-with
// Matches class names starting with "icon-"
//span[starts-with(@class, 'icon-')]
// Matches class names ending with "-active" (XPath 2.0+)
//div[ends-with(@class, '-active')]
2 Multiple inclusion filtering
Locate class names that contain multiple keywords at the same time (the order does not matter):
//div[contains(@class, 'user') and contains(@class, 'admin')]
3. Class name normalization
Use normalize-space() to eliminate extra spaces:
//div[contains(normalize-space(@class), 'selected')]
The impact of AI and visualization tools on XPath positioning
AI intelligent generation: Automated XPath generation tools based on visual recognition (such as Testim and Applitools) can analyze the page structure and automatically output optimized paths including classes;
Browser DevTools enhancement: Chrome's latest developer tools now support the generation of contains(@class) expressions by right-clicking an element;
Cross-frame adapter: For Web Components and Shadow DOM, XPath positioning needs to be combined with shadow-root penetration technology:
//custom-element::shadow-root//div[contains(@class, 'inner-component')]
Conclusion
In web crawling and automated testing, the proper use of the class contains selector can significantly improve the robustness of the script. When faced with large-scale data collection, combined with abcproxy's high-quality proxy IP services (such as static residential proxies or data center proxies), it can effectively bypass the anti-crawling mechanism and ensure the stability of the XPath positioning process. If you need to achieve efficient and secure network request management in complex scenarios, you can visit the abcproxy official website to explore customized solutions.
Featured Posts
Popular Products
Residential Proxies
Allowlisted 200M+ IPs from real ISP. Managed/obtained proxies via dashboard.
Residential (Socks5) Proxies
Over 200 million real IPs in 190+ locations,
Unlimited Residential Proxies
Use stable, fast, and furious 700K+ datacenter IPs worldwide.
Rotating ISP Proxies
ABCProxy's Rotating ISP Proxies guarantee long session time.
Residential (Socks5) Proxies
Long-lasting dedicated proxy, non-rotating residential proxy
Dedicated Datacenter Proxies
Use stable, fast, and furious 700K+ datacenter IPs worldwide.
Web Unblocker
View content as a real user with the help of ABC proxy's dynamic fingerprinting technology.
Related articles
How does idope improve data collection efficiency
This article explores the core role of idope in data collection, analyzes how proxy IP can optimize its operating efficiency, and analyzes the adaptation solution provided by abcproxy.
Big Data Ecommerce: Core Value and Application
This article discusses the technical architecture and commercial value of Big Data Ecommerce, and analyzes the transformation path of the e-commerce industry driven by data. abcproxy provides underlying support for big data e-commerce through proxy IP services, helping enterprises achieve precise operations.
Class in XPath: Syntax, Application and Advanced
This article systematically explains the core principles and practical applications of the contains(@class, 'value') selector in XPath, covering key scenarios such as dynamic class name processing, multiple class name matching, performance optimization, and provides solutions to deal with the complex class name structure of modern Web frameworks.