Python selenium文件上傳下載功能代碼實(shí)例
上傳
html文件內(nèi)容如下:操作步驟
<html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <title>upload_file</title> <script type="text/javascript" async="" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <link rel="external nofollow" rel="stylesheet" /> <script type="text/javascript"> </script> </head> <body> <div class="row-fluid"> <div class="span6 well"> <h3>upload_file</h3> <input type="file" name="file" /> </div> </div> </body> <script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script> </html>
python上傳源碼
#coding=utf-8
from selenium import webdriver
import time
driver = webdriver.Chrome()
#打開上傳文件頁(yè)面
driver.get("D://unload.html")
#定位上傳位置,添加本地文件
upload = driver.find_element_by_name("file")
upload.send_keys('D://run.py')
#打印上傳值
print (upload.get_attribute('value'))
time.sleep(2)
driver.quit()
上傳文件結(jié)果

python下載文件源碼
# -*- coding: utf-8 -*-
from selenium import webdriver
from time import sleep
options = webdriver.ChromeOptions()
#profile.default_content_settings.popups:設(shè)置為 0 禁止彈出窗口 download.default_directory:設(shè)置下載路徑
prefs = {'profile.default_content_settings.popups': 0, 'download.default_directory': 'd:\\921'}
options.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome(chrome_options=options)
#打開下載地址
driver.get('http://npm.taobao.org/mirrors/chromedriver/2.13/')
#點(diǎn)擊下載鏈接下載
driver.find_element_by_xpath('/html/body/div[1]/pre/a[3]').click()
sleep(3)
driver.quit()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Python SELENIUM上傳文件或圖片實(shí)現(xiàn)過(guò)程
- Selenium瀏覽器自動(dòng)化如何上傳文件
- selenium+python實(shí)現(xiàn)文件上傳操作的方法實(shí)例
- Python爬蟲中Selenium實(shí)現(xiàn)文件上傳
- 基于python的selenium兩種文件上傳操作實(shí)現(xiàn)詳解
- python+selenium+autoit實(shí)現(xiàn)文件上傳功能
- Python中selenium實(shí)現(xiàn)文件上傳所有方法整理總結(jié)
- Python selenium文件上傳方法匯總
- Python中Selenium上傳文件的幾種方式
相關(guān)文章
Python標(biāo)準(zhǔn)庫(kù)之循環(huán)器(itertools)介紹
這篇文章主要介紹了Python標(biāo)準(zhǔn)庫(kù)之循環(huán)器(itertools)介紹,本文講解了無(wú)窮循環(huán)器、函數(shù)式工具、組合工具、groupby()、其它工具等內(nèi)容,需要的朋友可以參考下2014-11-11
Python詞云的正確實(shí)現(xiàn)方法實(shí)例
這篇文章主要給大家介紹了關(guān)于Python詞云的正確實(shí)現(xiàn)方法的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-05-05
python破解bilibili滑動(dòng)驗(yàn)證碼登錄功能
這篇文章主要介紹了python破解bilibili滑動(dòng)驗(yàn)證碼登錄功能,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09
django實(shí)現(xiàn)登錄時(shí)候輸入密碼錯(cuò)誤5次鎖定用戶十分鐘
這篇文章主要介紹了django實(shí)現(xiàn)登錄時(shí)候輸入密碼錯(cuò)誤5次鎖定用戶十分鐘,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-11-11
python深度學(xué)習(xí)之多標(biāo)簽分類器及pytorch實(shí)現(xiàn)源碼
這篇文章主要為大家介紹了python深度學(xué)習(xí)之多標(biāo)簽分類器的使用說(shuō)明及pytorch的實(shí)現(xiàn)源碼,有需要的朋友可以借鑒參考下,希望能夠有所幫助2022-01-01
OpenCV圖像修復(fù)cv2.inpaint()的使用
這篇博客將介紹如何通過(guò)OpenCV中圖像修復(fù)的技術(shù)——cv2.inpaint() 去除舊照片中的小噪音、筆劃等。并提供一個(gè)可交互式的程序,感興趣的可以了解一下2021-08-08
Pandas Shift函數(shù)的基礎(chǔ)入門學(xué)習(xí)筆記
shift函數(shù)是對(duì)數(shù)據(jù)進(jìn)行移動(dòng)的操作,下面這篇文章主要給大家介紹了關(guān)于Pandas Shift函數(shù)的基礎(chǔ)入門學(xué)習(xí)筆記,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-11-11

