0
点赞
收藏
分享

微信扫一扫

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: [obje

WikongGuan 2022-04-08 阅读 97

我自己感觉出现这种问题是反扒造成的,故我查看了window.navigator.webdriver
在这里插入图片描述

正常使用网页
在这里插入图片描述
爬虫爬取网页
在这里插入图片描述
故我先修改了该参数的值,发现问题解决了

在这里插入图片描述
最后淘宝登陆成功

如果我们没有处理该参数的话,我们可能面临需要滑动模块的情况,但是应该是淘宝检测到我们是自动控制浏览器,在设置拖拽的代码时,发现没有效果

btn = web.find_element_by_xpath('//*[@id="nc_1_n1z"]')
ActionChains(web).drag_and_drop_by_offset(btn, 300, 0).perform()

以下是爬取淘宝购物车的完整代码


from selenium.webdriver import Chrome
from selenium.webdriver.common.action_chains import ActionChains
import time
from selenium.webdriver.chrome.options import Options


# 2.chrome的版本大于等于88
option = Options()
# option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_argument('--disable-blink-features=AutomationControlled')

web = Chrome(options=option)

# web = Chrome()
#https://login.taobao.com/member/login.jhtml?spm=a21bo.jianhua.754894437.1.5af911d9cFMyao&f=top&redirectURL=https%3A%2F%2Fwww.taobao.com%2F
web.get('https://www.taobao.com/')
time.sleep(2)
web.find_element_by_xpath('//*[@id="J_SiteNavLogin"]/div[1]/div[1]/a[1]').click()
time.sleep(2)
web.find_element_by_xpath('//*[@id="login"]/div[2]/div/div[1]/a[1]').click()

time.sleep(2)

web.find_element_by_xpath('//*[@id="fm-login-id"]').send_keys('用户名')
# //*[@id="fm-login-password"]
web.find_element_by_xpath('//*[@id="fm-login-password"]').send_keys('密码')

#//*[@id="nc_1_n1z"]


web.find_element_by_xpath('//*[@id="login-form"]/div[4]/button').click()

time.sleep(5)
# # # 拖拽
# btn = web.find_element_by_xpath('//*[@id="nc_1_n1z"]')
# ActionChains(web).drag_and_drop_by_offset(btn, 300, 0).perform()



web.find_element_by_xpath('//*[@id="J_MiniCart"]/div[1]/a').click()



举报

相关推荐

0 条评论