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-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:設(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í)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)2. asp(vbscript)中自定義函數(shù)的默認(rèn)參數(shù)實(shí)現(xiàn)代碼3. 如何使用瀏覽器擴(kuò)展篡改網(wǎng)頁中的JS 文件4. JSP servlet實(shí)現(xiàn)文件上傳下載和刪除5. jsp中sitemesh修改tagRule技術(shù)分享6. Ajax實(shí)現(xiàn)表格中信息不刷新頁面進(jìn)行更新數(shù)據(jù)7. 爬取今日頭條Ajax請(qǐng)求8. JavaWeb Servlet中url-pattern的使用9. ASP基礎(chǔ)知識(shí)VBScript基本元素講解10. jsp EL表達(dá)式詳解
