Skip to content Skip to sidebar Skip to footer

Need To Get Html Source As String Cefpython

I am trying to get HTML source as string from web URL using CEFPython I want MainFrame's source content to be crawled and get string in def save_screenshot(browser): # Bro

Solution 1:

Your mainframe.GetSource(visitor) is asynchronous. Therefore you cannot call GetString() from it.

This is the way to do, unfortunately you need to think in asynchronous manner:

classVisitor(object)
    defVisit(self, value):
        print("This is the HTML source:")
        print(value)
myvisitor = Visitor()
mainFrame = browser.GetMainFrame()
mainFrame.GetSource(myvisitor)

One more thing to beware of: the visitor object myvisitor in the above example is passed on to GetSource() in weak reference. In other words, you must keep that object alive until the source is passed back. If you put the last three lines in the above snippet in a function, you have to make sure the function does not return until the job is done.

Post a Comment for "Need To Get Html Source As String Cefpython"