本篇文章是接着第一篇文章講的
具體可看第一篇:https://www.cnblogs.com/whatarey/p/10477754.html
要實現功能》搜索完畢,自動點擊
這個功能做的停操蛋的,(忍不住想罵人)
按照我的做好,F12看看第一個a標簽class 或者id,然后使用
find_element_by_id找到,點擊就可以了
可是,他沒有id,沒有class 也沒有name
沒辦法了,假如遇到這種情況,
find_element_by_xpath 使用這個
然后
("div[@id='1']/h3/a").click()
卧槽,他報錯,說找不到指定的位置~~這很尷尬,然后又重新弄
看文檔找到了一個 get_attribute 獲取方法
結果也沒用~~死活報錯~~死活找不到
后面又找到一個辦法
先引用from selenium.webdriver.common.action_chains import
ActionChains(seleniumGoo).move_by_offset(x,y).click().perform()
鼠標左鍵點擊
ActionChains(seleniumGoo).move_by_offset(x, y).context_click().perform() # 鼠標右鍵點擊
我去
,我就用這個辦法做出來的
ActionChains(seleniumGoo).move_by_offset(-480, 126).click().perform() # 鼠標左鍵點擊x坐標,y坐標
demo:
# coding:utf8 from selenium import webdriver import time from selenium.webdriver.common.action_chains import ActionChains def Mian(): seleniumGoo=webdriver.Chrome() seleniumGoo.get("https:www.baidu.com") seleniumGoo.find_element_by_xpath() #seleniumGoo.find_element_by_id("kw") seleniumGoo.find_element_by_id("kw").send_keys("Cgrain博客園") seleniumGoo.find_element_by_id('su').click() time.sleep(2) ActionChains(seleniumGoo).move_by_offset(-480, 126).click().perform() # 鼠標左鍵點擊, 200為x坐標, 100為y坐標 #time.sleep(2) #("div[@id='1']/h3/a").click() #ActionChains(seleniumGoo).move_by_offset(-480, 126).context_click().perform() # 鼠標右鍵點擊 time.sleep(20) if __name__ == "__main__": Mian()
End,脫坑,覺得好的話點個關注+贊哦