我正在尝试使用selenium chromedriver将文件上传到facebook组.
driver.find_element_by_xpath("//input[@type='file']").send_keys("http://www.peta.org/wp-content/uploads/2013/10/goat_2D00_list_2D00_1.jpg")
但它会抛出一个例外:
selenium.common.exceptions.WebDriverException: Message: unkNown error:
path is not absolute:
我在Windows 10,Chrome 44.0.2403.130,ChromeDriver 2.16.333243,selenium 2.47.1
解决方法:
driver.find_element_by_xpath("//input[@type='file']").send_keys("/Path/to/the/file")
首先下载图像,然后上传.例如:
用urllib
import os
import urllib
base_dir = "/Path/to/dir/"
path_to_image = os.path.join(base_dir, "upload.jpg")
urllib.urlretrieve("http://www.peta.org/wp-content/uploads/2013/10/goat_2D00_list_2D00_1.jpg", path_to_image)
driver.find_element_by_xpath("//input[@type='file']").send_keys(path_to_image)
有要求
import os
import requests
base_dir = "/Path/to/dir/"
path_to_image = os.path.join(base_dir, "upload.jpg")
response = requests.get("http://www.peta.org/wp-content/uploads/2013/10/goat_2D00_list_2D00_1.jpg")
if response.status_code == 200:
f = open(base_dir + path_to_image, 'wb')
f.write(response.content)
f.close()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。