时间:2020-07-21 python运维 查看: 951
上传
html文件内容如下:操作步骤
<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 href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.min.css" 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()
上传文件结果
python下载文件源码
# -*- coding: utf-8 -*-
from selenium import webdriver
from time import sleep
options = 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()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持python博客。