<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hello all,<div><br></div><div>I'm using a QtWebKit.QWebView widget to display some content in an app.</div><div><br></div><div>The app generates html, then displays it in the QWebView widget using setHtml().</div><div><br></div><div>After the data is displayed, under certain circumstances, I need to walk through the elements in the page, find certain tags and adjust them. </div><div><br></div><div>This all works quite well the first time one of the QWebViews is displayed (actually, it seems to work best on the *second* page viewed, not the first). However, if the user requests to look at a different page (which then just calls setHtml again, but with different data), while the page is displayed correctly, the traversal fails. In fact, if I try to fetch the html data with self.page().mainFrame().toHtml(), the html returned is truncated. Again, the data is correctly displayed, but I can't seem to get or traverse the html.</div><div><br></div><div>I can't really put together a working example, but here's some of the important bits:</div><div><br></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><div>- My class inherits from QtWebKit.QWebView</div><div>- When requested by the user, html is generated and stored in a string which is pushed to the page with self.setHtml(data). That string contains everything from the opening html tag to the closing html tag - head, script, body, etc. tags included.</div><div>- After the page is displayed, the QWebElements of the page are traversed, some of which are modified.</div><div>- I've been checking that the data was set correctly by writing it out to tmp files: 1.html (which comes from fp.write(data) where "data" is the same string that was used in setHtml(data)) and 2.html (which comes from self.page().mainFrame().toHtml()).</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>1.html looks like I expect it to - a fully formed html page that can also be viewed by other web browsers.</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>2.html is a truncated version of 1.html. Always truncated in the same spot. If it matters, it's truncated after the second script tag is closed. There's also a closing html tag appended to it.</div><div>- traversal happens like so:</div></blockquote><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"> document = self.page().mainFrame().documentElement()<br> self.examineChildElements(document)<div style="text-align: left;"><br></div><div style="text-align: left;"><div style="text-align: left;">def examineChildElements(self, parentElement):</div><div style="text-align: left;"> element = parentElement.firstChild()</div><div style="text-align: left;"> while not element.isNull():</div><div style="text-align: left;"><span class="Apple-tab-span" style="white-space:pre"> </span> if re.match(self.__exrpat,element.attribute("data-original")):</div><div style="text-align: left;"><span class="Apple-tab-span" style="white-space:pre"> </span>doStuff()</div><div style="text-align: left;"> self.examineChildElements(element)</div><div style="text-align: left;"> element = element.nextSibling()</div><div style="text-align: left;"><br></div></div></blockquote></blockquote>To be clear, the question is this: Why, after calling setHtml, modifying some tags, then setHtml again, does self.page().mainFrame().toHtml() not give me correct html (the stuff from the second setHtml()) back? Should I not be re-using the same page and calling setHtml over and over again? <div>At the end of the day, I want to be able to generate some html, display it, possibly modify it, then generate different html, display it, possibly modify it, etc, etc, etc.<br><div><br></div><div>Thanks,</div><div>-Brian</div></div></body></html>