Search code examples
pythonparsingwebdryscrape

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


Solution

  • 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