How to close the browser after completing a download?

前端 未结 3 1192
一向
一向 2021-01-04 08:28

How to make browser closed after completing download?

from selenium import webdriver
from selenium.webdriver.common.keys import Keys

browser = webdriver         


        
3条回答
  •  猫巷女王i
    2021-01-04 08:50

    This is an alternative way I did on C#. Maybe you can use the same technique and apply it on python.

    public static string GetRequest(string url, bool isBinary = false) {
        // binary is the file that will be downloaded
        // Here you perform asynchronous get request and download the binary
        // Python guide for GetRequest -> http://docs.python-requests.org/en/latest/user/quickstart/
    }
    
    browser.webdriver.Firefox();
    browser.get(any_url);
    elem = browser.findElement("locator");
    GetRequest(elem.getAttribute('href'), true); // when this method is done, you expect the get request is done
    browser.quit();
    

提交回复
热议问题