网站设计首页框架图片,域名防红直连,温州英文seo,wordpress滑动验证码本篇文章小编给大家分享一下Python自动化xpath实现自动抢票抢货代码示例#xff0c;文章代码介绍的很详细#xff0c;小编觉得挺不错的#xff0c;现在分享给大家供大家参考#xff0c;有需要的小伙伴们可以来看看。
总代码#xff1a;
for i in range(51,56):
driver.imp…本篇文章小编给大家分享一下Python自动化xpath实现自动抢票抢货代码示例文章代码介绍的很详细小编觉得挺不错的现在分享给大家供大家参考有需要的小伙伴们可以来看看。
总代码
for i in range(51,56):
driver.implicitly_wait(10)
ActionChains(driver).move_to_element(driver.find_element_by_xpath(//*[idsave-results-panel-trigger])).click().perform()
Select(driver.find_element_by_xpath(//*[idsave-action-selection])).select_by_visible_text(All results on this page)
ActionChains(driver).move_to_element(driver.find_element_by_xpath(//*[idsave-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(//*[idsave-action-panel-form]/div[3]/button[1])).click().perform()
target driver.find_element_by_xpath(//*[idsearch-results]/section/div[3]/a/span)
driver.execute_script(arguments[0].();, target)
ActionChains(driver).move_to_element(driver.find_element_by_xpath(//*[idsearch-results]/section/div[3]/a/span)).click().perform()
ActionChains(driver).move_to_element(driver.find_element_by_xpath(//*[idsearch-page]/div[12]/div/form/button)).click().perform()
print(第str(i)页下载成功)
print(跳转第str(i1)页面中)
driver.quit()
print(全部下载完毕自动退出。)
代码1for i in range(1,501): 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(全部下载完毕结束了)
因为这两句代码已经不是循环体的内容了所以无需另起一行空两个而且小伙伴记得噢所有字符都是英文字符包括括号、引号等等。