python抢货程序_Python自动化xpath实现自动抢票抢货代码示例
本篇文章小編給大家分享一下Python自動化xpath實現自動搶票搶貨代碼示例,文章代碼介紹的很詳細,小編覺得挺不錯的,現在分享給大家供大家參考,有需要的小伙伴們可以來看看。
總代碼:
for i in range(51,56):
driver.implicitly_wait(10)
ActionChains(driver).move_to_element(driver.find_element_by_xpath('//*[@id="save-results-panel-trigger"]')).click().perform()
Select(driver.find_element_by_xpath('//*[@id="save-action-selection"]')).select_by_visible_text("All results on this page")
ActionChains(driver).move_to_element(driver.find_element_by_xpath('//*[@id="save-action-format"]')).click().perform()
Select(driver.find_element_by_xpath('/html/body/main/div[1]/div/form/div[2]/select')).select_by_visible_text("CSV")
ActionChains(driver).move_to_element(driver.find_element_by_xpath('//*[@id="save-action-panel-form"]/div[3]/button[1]')).click().perform()
target =driver.find_element_by_xpath('//*[@id="search-results"]/section/div[3]/a/span')
driver.execute_script("arguments[0].();", target)
ActionChains(driver).move_to_element(driver.find_element_by_xpath('//*[@id="search-results"]/section/div[3]/a/span')).click().perform()
ActionChains(driver).move_to_element(driver.find_element_by_xpath('//*[@id="search-page"]/div[12]/div/form/button')).click().perform()
print('第'+str(i)+'頁下載成功')
print('跳轉第'+str(i+1)+'頁面中')
driver.quit()
print('全部下載完畢,自動退出。')
代碼1
for i in range(1,50+1): printg('我錯了')
操作如下:鼠標移動到Save按鈕→鼠標右擊→檢查,
可以發現源代碼有一塊區域亮起來了
這塊區域就是Save按鈕對應的源代碼→鼠標移動到該源代碼區域→右擊→復制→復制XPath,
這樣我們就復制了Save按鈕的Xpath了,接下來只需要粘貼到代碼就行.
小伙伴們是否還記得ActionChains的萬能公式:
ActionChains(driver).move_to_element(driver.find_element_by_xpath('xpath_content')).click().perform()
我們只需要把剛才復制的xpath粘貼到代碼中的“xpath_content”區域就行
是不是很熟悉呢,是的,這便是我們使用ActionChains模塊實現的第一個操作,后續的一樣噢,只需要復制對應的Xpath直接粘貼就行了。
最后,因為以上均是循環體的內容,當代碼執行完整個循環體了,我們可以通過代碼直接關掉瀏覽器,提醒我們打印完了,代碼如下
driver.quit()
print('全部下載完畢,結束了')
因為這兩句代碼已經不是循環體的內容了,所以無需另起一行空兩個,而且,小伙伴記得噢,所有字符都是英文字符,包括括號、引號等等。
總結
以上是生活随笔為你收集整理的python抢货程序_Python自动化xpath实现自动抢票抢货代码示例的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 分布式锁与实现(一)——基于Redis实
- 下一篇: 《Python从小白到大牛》简介