如何使用IMPORTXML查找含playerlocation的方格并提取坐标?
定位含playerlocation的方格及坐标提取方案
1. 精准匹配目标方格的XPath表达式
要找到包含playerlocation类的方格,直接用XPath的contains()函数即可,结合你提供的地图根路径,最终表达式为:
/html/body/div/div/div[3]/div/div[2]/div/div/table/tbody//td[contains(@class, 'playerlocation')]
2. 表达式解析
//td:从地图的tbody节点开始,递归查找所有层级的td方格元素,无需逐个指定行和列位置contains(@class, 'playerlocation'):匹配class属性中包含playerlocation字符串的td元素,兼容class里同时存在坐标、区域名称等其他值的情况
3. 坐标提取方法
拿到匹配的td元素后,从其class属性中提取坐标:
- 先获取完整的class属性值,例如:
coord x1054 y987 secronomBunker playerlocation - 使用正则表达式
x(\d+)和y(\d+)分别提取x、y的数字部分,最终组合成x#### y####格式的坐标字符串
内容的提问来源于stack exchange,提问作者Dat Guy
相关产品推荐
相关产品推荐

