今天踩了一個坑:
? ? 需要使用selenium-wire抓取請求heads信息,直接用命令 pip install?selenium-wire安裝后,調(diào)試代碼一直報cannot import name 'TouchActions' from 'selenium.webdriver'
開發(fā)環(huán)境:
selenium? 版本4.11.2 (用 pip show selenium? 查看版本)
selenium-wire版本 2.5.2?(用 pip selenium-wire? 查看版本),用pip install selenium-wire命令沒有指定版本號安裝的
python? 3.7
一步一步跟進(jìn)問題:
1、在selenium-wire 的webdriver中有from selenium.webdriver import TouchActions,但是我安裝的selenium? 版本4.11.2已經(jīng)不使用TouchActions了 只使用ActionChains,然后在網(wǎng)上搜索到的解決辦法是 回退到selenium? 3.141.0 (pip install selenium ==3.141.0),但是此辦法不管用,報各種請求超時錯誤
2、既然selenium-wire版本 2.5.2使用TouchActions,而selenium? 版本4.11.2不使用TouchActions,那么是否有selenium-wire某個版本不使用TouchActions了呢,通過在https://www.cnpython.com/pypi/seleniumwire網(wǎng)上找到最新的selenium-wire 5.1.0解決問題,此版本支持selenium 4+版本?pip install selenium-wire ==5.1.0
總結(jié):文章來源:http://www.zghlxwxcb.cn/news/detail-721561.html
這種問題一般是版本不匹配導(dǎo)致,注意版本匹配即可文章來源地址http://www.zghlxwxcb.cn/news/detail-721561.html
到了這里,關(guān)于ImportError: cannot import name ‘TouchActions‘ from ‘selenium.webdriver‘的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!