Python selenium文件上傳下載功能代碼實例
更新時間:2020年04月13日 09:33:23 作者:天天向上327
這篇文章主要介紹了Python selenium文件上傳下載功能代碼實例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
上傳
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()
#打開上傳文件頁面
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/')
#點擊下載鏈接下載
driver.find_element_by_xpath('/html/body/div[1]/pre/a[3]').click()
sleep(3)
driver.quit()
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python標(biāo)準(zhǔn)庫之循環(huán)器(itertools)介紹
這篇文章主要介紹了Python標(biāo)準(zhǔn)庫之循環(huán)器(itertools)介紹,本文講解了無窮循環(huán)器、函數(shù)式工具、組合工具、groupby()、其它工具等內(nèi)容,需要的朋友可以參考下2014-11-11
django實現(xiàn)登錄時候輸入密碼錯誤5次鎖定用戶十分鐘
這篇文章主要介紹了django實現(xiàn)登錄時候輸入密碼錯誤5次鎖定用戶十分鐘,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-11-11
python深度學(xué)習(xí)之多標(biāo)簽分類器及pytorch實現(xiàn)源碼
這篇文章主要為大家介紹了python深度學(xué)習(xí)之多標(biāo)簽分類器的使用說明及pytorch的實現(xiàn)源碼,有需要的朋友可以借鑒參考下,希望能夠有所幫助2022-01-01
OpenCV圖像修復(fù)cv2.inpaint()的使用
這篇博客將介紹如何通過OpenCV中圖像修復(fù)的技術(shù)——cv2.inpaint() 去除舊照片中的小噪音、筆劃等。并提供一個可交互式的程序,感興趣的可以了解一下2021-08-08
Pandas Shift函數(shù)的基礎(chǔ)入門學(xué)習(xí)筆記
shift函數(shù)是對數(shù)據(jù)進(jìn)行移動的操作,下面這篇文章主要給大家介紹了關(guān)于Pandas Shift函數(shù)的基礎(chǔ)入門學(xué)習(xí)筆記,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-11-11

