Python selenium文件上傳下載功能代碼實例
上傳
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-8from selenium import webdriverimport timedriver = 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 webdriverfrom time import sleepoptions = webdriver.ChromeOptions()#profile.default_content_settings.popups:設置為 0 禁止彈出窗口 download.default_directory:設置下載路徑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)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. XML在語音合成中的應用2. jscript與vbscript 操作XML元素屬性的代碼3. 不要在HTML中濫用div4. HTML5實戰(zhàn)與剖析之觸摸事件(touchstart、touchmove和touchend)5. .NET Framework各版本(.NET2.0 3.0 3.5 4.0)區(qū)別6. ASP基礎(chǔ)入門第四篇(腳本變量、函數(shù)、過程和條件語句)7. ASP將數(shù)字轉(zhuǎn)中文數(shù)字(大寫金額)的函數(shù)8. XML入門的常見問題(三)9. php使用正則驗證密碼字段的復雜強度原理詳細講解 原創(chuàng)10. HTTP協(xié)議常用的請求頭和響應頭響應詳解說明(學習)
