我在python中使用dryscrape浏览网站,我需要将文件上传到此网站。但只有一种方法,即单击按钮并浏览我的文件并选择我想要的文件。我怎么能用python做到这一点?如果有人能帮助我使用dryscrape,我将不胜感激,但我接受了所有答案。
答案 0 :(得分: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()
资源
答案 1 :(得分:0)
对于那些在dryscrape中搜索答案的人,我将selenium代码翻译成了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")
就像它一样简单。