def getElementXpath(self, page): root = html.fromstring(page.content()) tree = root.getroottree() result = root.xpath('//*' )#'//*[. = * ]') for r in result: # eleTree = tree.getpath(r) eleXpath = '/' + tree.getpath(r) if page.locator(eleXpath).is_visible(): # 获取页面上的所有 button 类控件绝对路劲 if eleXpath.endswith('button'): pageElementXpath.append(eleXpath) # 获取页面上的所有 span(下拉) 类控件绝对路劲 if eleXpath.endswith('span'): pageElementXpath.append(eleXpath) # 获取页面上的所有 input(输入) 类控件绝对路劲 if eleXpath.endswith('input') or eleXpath.endswith('textarea'): print(eleXpath) pageElementXpath.append(eleXpath) # 获取页面上的所有 li(选项) 类控件绝对路劲 if '/ul' in eleXpath and (eleXpath.split('/')[-1]).startswith('li'): print(eleXpath) pageElementXpath.append(eleXpath) print('已获取到页面:{1}所有控件的绝对路径!') return pageElementXpath
Python 对HTML监控,获取页面可操作Node的绝对路径
最新推荐文章于 2024-09-27 10:11:28 发布