jamescaruso
jamescaruso

Reputation: 79

send files to a website through a 'browse files' on pc

I'm browsing through a website using dryscrape in python and i need to upload a file to this site. But there is only one way of doing it, that is clicking in a button and browse into my files and select the one i want. How can i do it with python? i would appreciate if someone could help me using dryscrape too, but i'm accepting all answers.

heres the example image: IMG

Upvotes: 1

Views: 168

Answers (2)

jamescaruso
jamescaruso

Reputation: 79

For those who are searching for the answer in dryscrape i translated the selenium code to 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")

just as simple as it is.

Upvotes: 0

Miguel
Miguel

Reputation: 20633

You can use Selenium. I tested this code and it works.

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()

Resources

Upvotes: 0

Related Questions