赞
踩
找到上传的标签,然后把本地文件路径发上去就可以了,可以是相对路径或绝对路径。
<input type="file" name="upload">
- from selenium import webdriver
-
- from selenium.webdriver.common.by import By
-
- from selenium.webdriver.common.keys import Keys
-
-
- browser = webdriver.Firefox()
-
-
- upload_button = browser.find_element(By.XPATH, "//input[@name='upload'][@type='file']")
-
- path_name="/home/user/Download/a.txt"
-
- upload_button.send_keys(path_name + Keys.RETURN)
Content-Type,内容类型,用于定义网络文件的类型和网页的编码,决定浏览器将以什么形式、什么编码读取这个文件。ContentType属性指定响应的 HTTP内容类型,如果未指定 ContentType,默认为TEXT/HTML。Content-Type常见有四种类型,分别是:application/x-www-form-urlencoded,multipart/form-data,application/json,text/xml。
如果是linux系统可以用命令:curl -I URL | grep "Content-Type"
或者用python代码:
- import requests
-
- content_type = requests.head('http://www.python.org').headers['content-type']
-
- print(content_type)
- #假如content-Type是application/octet-stream
-
- import os
-
-
- from selenium import webdriver
-
-
- fp = webdriver.FirefoxProfile()
-
-
- fp.set_preference("browser.download.folderList",2)
-
- fp.set_preference("browser.download.manager.showWhenStarting",False)
-
- fp.set_preference("browser.download.dir", os.getcwd())
-
- fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream")
- browser = webdriver.Firefox(firefox_profile=fp)
-
- browser.get("http://pypi.python.org/pypi/selenium")
-
- browser.find_element_by_partial_link_text("selenium-2").click()
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。