用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計算區域高度,座標原點爲網頁視圖左上角頂點,可通過計算後精準點擊某點