一、下載chrome瀏覽器和同版本的chromedriver
chrome測試版版本120.0.6099.109
鏈接:https://pan.baidu.com/s/1pvFqL0WN8OkqPmURAs83kg?pwd=vtsh
提取碼:vtsh
chromedriver版本120.0.6099.109
鏈接:https://pan.baidu.com/s/16fWWkrlD5C3JRfYRG_NjfQ?pwd=3d26
提取碼:3d26
二、修改系統(tǒng)環(huán)境
1.將chromedriver.exe放入chrome瀏覽器文件夾中
2.在系統(tǒng)環(huán)境中——編輯環(huán)境變量——雙擊Path——新建 F:\chrome-win64(你的chrome瀏覽器所在文件夾)
三、修改pycharm中python包
1.先安裝selenium
pip install selenium
2.卸載urllib3(selenium版本和urllib3版本不兼容)文章來源:http://www.zghlxwxcb.cn/news/detail-834233.html
pip uninstall urllib3
3.重新安裝urllib文章來源地址http://www.zghlxwxcb.cn/news/detail-834233.html
pip install urllib3==1.26.2
四、測試代碼 成功!
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
# 使用 Chrome 作為瀏覽器
driver = webdriver.Chrome()
# 打開網(wǎng)頁
driver.get("https://blog.csdn.net/weixin_44071904?type=blog")
# 獲取頁面標(biāo)題并打印
print(driver.title)
# 關(guān)閉瀏覽器
driver.quit()
到了這里,關(guān)于Pycharm配置運行selenium教程的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!