【问题标题】:send files to a website through a 'browse files' on pc通过电脑上的“浏览文件”将文件发送到网站
【发布时间】:2017-06-22 02:12:27
【问题描述】:

我正在使用 python 中的 dryscrape 浏览网站,我需要将文件上传到该网站。但是只有一种方法可以做到这一点,即单击一个按钮并浏览我的文件并选择我想要的那个。我怎么能用python做到这一点?如果有人也可以帮助我使用dryscrape,我将不胜感激,但我接受所有答案。

这里是示例图像:

【问题讨论】:

    标签: python parsing web dryscrape


    【解决方案1】:

    您可以使用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()
    

    资源

    【讨论】:

    • 谢谢兄弟,我忘了硒! :)
    【解决方案2】:

    对于那些在 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")
    

    就这么简单。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-07-03
      • 1970-01-01
      • 1970-01-01
      • 2011-01-29
      • 1970-01-01
      • 1970-01-01
      • 2014-11-15
      • 1970-01-01
      相关资源
      最近更新 更多