完成下载后如何关闭浏览器? [英] How to make browser closed after completing download?

查看:122
本文介绍了完成下载后如何关闭浏览器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

完成下载后如何关闭浏览器?

How to make browser closed after completing download?

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

browser = webdriver.Firefox()
browser.get(any_url)
browser.find_elements_by_xpath('//input[@value="Download"]').click()

# The program start downloading now.

# HERE WHAT IS THE CODE?

browser.quit()

我只想关闭浏览器完成下载。

I want to close the browser only after completing the download.

推荐答案

这是我在C#上做的另一种方法。也许你可以使用相同的技术,并将其应用于Python。

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

这篇关于完成下载后如何关闭浏览器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆