【发布时间】:2021-03-08 03:23:07
【问题描述】:
我想点击并按住网页中的栏并将其向右移动。
这是我的代码:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
browser = webdriver.Ie('IEDriverServer.exe')
url = 'https://verify.meituan.com/v2/web/general_page?action=spiderindefence&requestCode=507e224b8f0f447793ad3a03830984c8&platform=1000&adaptor=auto&succCallbackUrl=https%3A%2F%2Foptimus-mtsi.meituan.com%2Foptimus%2FverifyResult%3ForiginUrl%3Dhttp%253A%252F%252Fwww.dianping.com%252Fsearch%252Fkeyword%252F1%252F0_%2525E5%252590%25258D%2525E5%252588%25259B%2525E4%2525BC%252598%2525E5%252593%252581%252F10&theme=dianping'
browser.get(url)
slider = browser.find_element_by_xpath("//div[@id='yodaBoxWrapper']//div[@id='yodaMoveingBar']")
ActionChains(browser).click_and_hold(slider).move_by_offset(xoffset=50, yoffset=0).perform()
条不移动。
我的代码有什么问题?
非常感谢。
【问题讨论】:
-
只需将
chrome选项替换为ie选项。添加用户代理。在获取 url 后添加 time.sleep。而已。from selenium.webdriver.ie.options import Options -
您可能需要等待滑块可点击。但是,无论如何,您将无法完成验证码,因为这些操作应该被识别为基于脚本的
-
我尝试在 5 分钟后执行代码,但条形图没有移动。
-
@Chan 你添加了用户代理吗?
-
@阿布拉尔·艾哈迈德。我还没有添加用户代理。