用python的selenium写爬虫通过绝对坐标点击,坐标的获取方法

注:
适用于谷歌浏览器浏览器;
其中css选择器为目标区域的css表达式;

网页F12打开源代码,在console窗口输入
在这里插入图片描述

#
Left计算X坐标
document.querySelectorAll('css选择器')[0].getBoundingClientRect().left + document.documentElement.scrollLeft
#Top计算Y坐标
document.querySelectorAll('css选择器')[0].getBoundingClientRect().top + document.documentElement.scrollTop

若该css区域过大,需计算其区域大小

#width计算区域宽度
document.querySelectorAll('css选择器')[0].getBoundingClientRect().width
#height计算区域高度
document.querySelectorAll('css选择器')[0].getBoundingClientRect().height

坐标原点为网页视图左上角顶点,可通过计算后再去点击

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐