Python selenium文件上传下载功能代码实例
作者:天天向上327 时间:2021-04-24 07:21:28
上传
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()
来源:https://www.cnblogs.com/yiwenrong/p/12664833.html
标签:Python,selenium,上传,下载
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
详解利用装饰器扩展Python计时器
2023-04-08 20:32:16
python实现自动化办公邮件合并功能
2022-02-22 21:06:06
![](https://img.aspxhome.com/file/2023/1/81571_0s.png)
如何使用python对图片进行批量压缩详解
2022-12-05 04:22:25
![](https://img.aspxhome.com/file/2023/9/72959_0s.jpg)
教你用Python脚本快速为iOS10生成图标和截屏
2022-03-04 05:08:28
![](https://img.aspxhome.com/file/2023/1/86211_0s.png)
golang 中signal包的Notify用法说明
2023-07-19 19:06:36
python版百度语音识别功能
2023-02-28 09:56:34
![](https://img.aspxhome.com/file/2023/3/75303_0s.jpg)
去掉运行JavaScript时IE产生的警告栏
2008-09-11 18:07:00
![](https://img.aspxhome.com/file/UploadPic/20089/11/2008911181137794s.png)
如何用python给数据加上高斯噪声
2023-06-13 18:18:04
Javascript优化(文件瘦身)
2008-06-02 13:20:00
不同浏览器所支持的“事件”
2007-09-26 18:29:00
Python + selenium + crontab实现每日定时自动打卡功能
2021-06-10 19:45:42
![](https://img.aspxhome.com/file/2023/6/84926_0s.png)
用pickle存储Python的原生对象方法
2023-10-31 04:43:13
轻松了解数据库计算机的概念和发展方向
2009-01-23 13:55:00
Python如何定义有默认参数的函数
2023-08-05 14:38:30
详解如何在CentOS7中使用Nginx和PHP7-FPM安装Nextcloud
2023-11-10 04:55:49
![](https://img.aspxhome.com/file/2023/8/75058_0s.png)
ThinkPHP5中如何使用redis
2023-06-13 01:09:10
![](https://img.aspxhome.com/file/2023/9/55499_0s.png)
扩展数据库系统选项实现更高的可扩展性
2009-01-06 11:14:00
使用python刷访问量的示例代码
2023-11-09 12:55:30
运行tensorflow python程序,限制对GPU和CPU的占用操作
2022-07-03 02:49:26
对python中的pop函数和append函数详解
2021-10-09 09:11:32
![](https://img.aspxhome.com/file/2023/5/93875_0s.gif)