[PyQt] QWebkit: saving/caching user input

Andreas Pakulat apaku at gmx.de
Wed Jan 18 08:34:19 GMT 2012

On 17.01.12 18:24:50, James Polk wrote:
> okay, Back at the front,...
> Let's say we use QWebKit to read an HTML file containing a javascript textField...like so:
> <html><body>
> <p>
>     <form name="thisForm">
>         <tr>
>             <td>Name:</td> <td><input type=text name="name" id="nameId" value="John"></td>
>         </tr>
>     </form>
> </body></html>
> When displayed,..the user types "Mary" into the field, replacing "John".
> Then using a method I, uh...derived...from a related web example...
> We want to "capture" the HTML being displayed and save it out to file....
> But,..we need the resulting file to contain the new user input text "Mary"...not John...
> so that on subsequent reloads, the HTML textField will display "Mary",etc...
> Here's the snippet to cache...
>     def DoIt(self):
>         print "Saving..."
>         data = self.webview.page().mainFrame().toHtml()
>         thisFile = "test.html"
>         open(QtCore.QString(thisFile), 'w').write(data)
>         print "Done!"
> However, it saves out "John" instead of "Mary"....
> Can anybody offer any solutions to this ?

File a bugreport with Nokia that they DOM-API is broken.

> And/or offer any other suggestions or workarounds to accomplish same ?

You could try evaluateJavaScript("document.innerHTML") or
evaluateJavaScript("document.body.innerHTML") (the latter will not
include the headers and the body-attributes though) to get the HTML
of the page via JS which apparently always works.


More information about the PyQt mailing list