詳解mac python+selenium+Chrome 簡單案例
更新時間:2019年11月08日 15:41:01 作者:冒牌技術(shù)小哥
這篇文章主要介紹了詳解mac python+selenium+Chrome 簡單案例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
第一步:下載selenium
pip install selenium
第二步:下載和你當(dāng)前谷歌瀏覽器對應(yīng)的驅(qū)動Chromedriver
下載地址:https://npm.taobao.org/mirrors/chromedriver
這是我谷歌對應(yīng)的版本,點(diǎn)擊選擇下載對應(yīng)的系統(tǒng)文件,下載完解壓到你項目的目錄里即可!
第三步:簡單操作selenium
from selenium import webdriver import time # 創(chuàng)建Chrome的驅(qū)動對象 driver = webdriver.Chrome('這里寫你剛下載的Chromedriver的地址即可') # 加載頁面 百度首頁 driver.get("http://www.baidu.com") # 保存當(dāng)前界面 driver.save_screenshot("baidu.png") # 搜索傳智播客 driver.find_element_by_id("kw").send_keys("selenium") # 點(diǎn)擊搜索按鈕 driver.find_element_by_id("su").click() # 獲取頁面內(nèi)容 # print(driver.page_source) #這個內(nèi)容就和Elements中內(nèi)容一樣 # 獲取當(dāng)前的URL print(driver.current_url) # 獲取cookie信息 cookies = driver.get_cookies() # print(cookies) # 處理成為我們發(fā)送請求時候,可以使用cookie cookies = {cookie["name"]:cookie["value"] for cookie in cookies} print(cookies) time.sleep(3) # 關(guān)閉當(dāng)前窗口 # driver.close() # 退出瀏覽器 driver.quit()
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- 下載與當(dāng)前Chrome對應(yīng)的chromedriver.exe(用于python+selenium)
- Python selenium 自動化腳本打包成一個exe文件(推薦)
- 基于python+selenium的二次封裝的實現(xiàn)
- python selenium 執(zhí)行完畢關(guān)閉chromedriver進(jìn)程示例
- python selenium循環(huán)登陸網(wǎng)站的實現(xiàn)
- springboot使用@value讀取配置的方法
- Python SELENIUM上傳文件或圖片實現(xiàn)過程
- 詳解pyinstaller selenium python3 chrome打包問題
- Python使用selenium + headless chrome獲取網(wǎng)頁內(nèi)容的方法示例
- Python Selenium參數(shù)配置方法解析
相關(guān)文章
python3.5 + PyQt5 +Eric6 實現(xiàn)的一個計算器代碼
這篇文章主要介紹了python3.5 + PyQt5 +Eric6 實現(xiàn)的一個計算器代碼,在windows7 32位系統(tǒng)可以完美運(yùn)行 計算器,有興趣的可以了解一下。2017-03-03Python運(yùn)行報錯UnicodeDecodeError的解決方法
本文給大家分享的是在Python項目中經(jīng)常遇到的關(guān)于編碼問題的一個小bug的解決方法以及分析方法,有相同遭遇的小伙伴可以來參考下2016-06-06