用python的selenium写爬虫通过绝对坐标点击,坐标的获取方法(谷歌浏览器):
网页F12打开源代码,在console窗口输入
document.querySelectorAll(‘css选择器’)[0].getBoundingClientRect().left + document.documentElement.scrollLeft
document.querySelectorAll(‘css选择器’)[0].getBoundingClientRect().top + document.documentElement.scrollTop
其中css选择器为目标区域的css表达式,Left计算X坐标,Top计算Y坐标,若该css区域过大,需计算其区域大小:
document.querySelectorAll(‘css选择器’)[0].getBoundingClientRect().width
document.querySelectorAll(‘css选择器’)[0].getBoundingClientRect().height
width计算区域宽度,height计算区域高度,坐标原点为网页视图左上角顶点,可通过计算后精准点击某点