Downloading file using IE from python

后端 未结 8 914
无人及你
无人及你 2021-02-04 15:38

I\'m trying to download file with Python using IE:

from win32com.client import DispatchWithEvents

class EventHandler(object):
    def OnDownloadBegin(self):
            


        
8条回答
  •  走了就别回头了
    2021-02-04 16:09

    One option could also be to embed your own browser.

    Thats e.g. possible with Qt via PyQt (GPL) or PySide (LGPL). There you could embed the WebKit engine. You could then either display the page in a QWebView and let the user navigate to your download and filter that event or use a simple QWebPage where everything could be automated and nothing has to be shown at all.

    And WebKit should be mighty enough to do anything you want.

    Very basic example:

    import sys
    
    from PySide import QtCore, QtGui, QtWebKit
    
    url = 'http://developer.qt.nokia.com/wiki/PySideDownloads/'
    
    class TestKit(QtCore.QObject):
        def __init__(self, app):
            self.page = QtWebKit.QWebPage()
            self.page.loadFinished.connect(self.finished)
            self.page.mainFrame().load(QtCore.QUrl(url))
            self.app = app
    
        def finished(self, evt):
            # inspect DOM -> navigate to next page or download
            print self.page.currentFrame().documentElement().toInnerXml().encode(
                    'utf-8')
            # when everything is done
            self.app.quit()
    
    
    if __name__ == '__main__':
        app = QtGui.QApplication(sys.argv)
        t = TestKit(app)
        sys.exit(app.exec_())
    

提交回复
热议问题