2017-06-22 51 views
1

我正在浏览一个使用python中的dryscrape的网站,我需要将文件上传到此网站。但只有一种方法可以做到这一点,即点击按钮并浏览我的文件并选择我想要的。我如何用python来做到这一点?如果有人能帮助我使用dryscrape,我将不胜感激,但我接受所有答案。通过电脑上的“浏览文件”将文件发送到网站

继承人的示例图像: IMG

回答

0

您可以使用Selenium。我测试了这个代码,它工作。

from selenium import webdriver 

url = "https://example.com/" 

driver = webdriver.Chrome("./chromedriver") 
driver.get(url) 

input_element = driver.find_element_by_css_selector("input[type=\"file\"]") 

# absolute path to file 
abs_file_path = "/Users/foo/Downloads/bar.png" 
input_element.send_keys(abs_file_path) 

sleep(5) 

driver.quit() 

资源

+0

感谢兄弟,我忘了硒! :) – jamescaruso

0

对于那些谁正在寻找dryscrape答案我翻译的硒代码dryscrape:

element = sessin.at_xpath("xpath...") # Session is a dryscrape session 
# The xpath is from the button like the one in the image "Browse..." 
element.set("fullpath") 

就像它一样简单。