python抢货程序_Python自动化xpath实现自动抢票抢货代码示例
本篇文章小編給大家分享一下Python自動化xpath實現(xiàn)自動搶票搶貨代碼示例,文章代碼介紹的很詳細(xì),小編覺得挺不錯的,現(xiàn)在分享給大家供大家參考,有需要的小伙伴們可以來看看。
總代碼:
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('跳轉(zhuǎn)第'+str(i+1)+'頁面中')
driver.quit()
print('全部下載完畢,自動退出。')
代碼1
for i in range(1,50+1): printg('我錯了')
操作如下:鼠標(biāo)移動到Save按鈕→鼠標(biāo)右擊→檢查,
可以發(fā)現(xiàn)源代碼有一塊區(qū)域亮起來了
這塊區(qū)域就是Save按鈕對應(yīng)的源代碼→鼠標(biāo)移動到該源代碼區(qū)域→右擊→復(fù)制→復(fù)制XPath,
這樣我們就復(fù)制了Save按鈕的Xpath了,接下來只需要粘貼到代碼就行.
小伙伴們是否還記得ActionChains的萬能公式:
ActionChains(driver).move_to_element(driver.find_element_by_xpath('xpath_content')).click().perform()
我們只需要把剛才復(fù)制的xpath粘貼到代碼中的“xpath_content”區(qū)域就行
是不是很熟悉呢,是的,這便是我們使用ActionChains模塊實現(xiàn)的第一個操作,后續(xù)的一樣噢,只需要復(fù)制對應(yīng)的Xpath直接粘貼就行了。
最后,因為以上均是循環(huán)體的內(nèi)容,當(dāng)代碼執(zhí)行完整個循環(huán)體了,我們可以通過代碼直接關(guān)掉瀏覽器,提醒我們打印完了,代碼如下
driver.quit()
print('全部下載完畢,結(jié)束了')
因為這兩句代碼已經(jīng)不是循環(huán)體的內(nèi)容了,所以無需另起一行空兩個,而且,小伙伴記得噢,所有字符都是英文字符,包括括號、引號等等。
總結(jié)
以上是生活随笔為你收集整理的python抢货程序_Python自动化xpath实现自动抢票抢货代码示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 分布式锁与实现(一)——基于Redis实
- 下一篇: 《Python从小白到大牛》简介