选择器练习场
练习 CSS 选择器、XPath 和 data 属性定位。在 Playwright 中使用 page.locator() 定位下方元素。
区域1:ID 选择器
目标:#unique-greeting,#special-offer
你好,爬虫学习者!
这个元素有唯一的 ID。试试:page.locator("#unique-greeting")
限时优惠:5 折
价格:¥99.99 ¥199.99
区域2:CSS 类选择器
目标:.product-card,.product-card.featured
Python 基础教程
¥29.99
Web 爬虫实战
¥49.99
数据分析入门
¥39.99
区域3:XPath 选择器
XPath 示例://div[@data-type='book'],//span[contains(text(),'章')]
Python 学习指南
12 章 入门高级 Web 爬虫
8 章 进阶Playwright 精讲
24 节课 中级区域4:数据属性选择器
目标:[data-category='tech'],[data-priority='high']
开发 REST API
截止:2026-06-01
设计落地页
截止:2026-05-15
编写单元测试
截止:2026-06-10
区域5:文本内容选择器
Playwright:page.get_by_text("提交订单"),page.get_by_role("button", name="确认支付")
区域6:嵌套/复杂选择器
定位深层嵌套元素:.comment-list .comment-item .author-name
写得很好,学到了很多!
能再详细讲讲选择器的部分吗?