snipt

Ctrl+h for KB shortcuts
#18354

Python

load jQuery into QWebView and evaluate some JavaScriipt

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *

myWebKit = QWebView()
myWebKit.show()

myWebKit.setUrl(QUrl("http://www.google.com"))

myWebKit.page().mainFrame().evaluateJavaScript(open('jquery.js').read())

myWebKit.page().mainFrame().evaluateJavaScript("""$(document).ready(function() { $("body").css("background", "#f00");});""")
https://snipt.net/embed/fe899722f4d364c7bed3cae9bdd265ee/
https://snipt.net/raw/fe899722f4d364c7bed3cae9bdd265ee/
fe899722f4d364c7bed3cae9bdd265ee
python
Python
12
2014-04-18T04:39:28
True
False
/api/public/snipt/18354/
load-jquery-into-qwebview-and-evaluate-some-javascriipt
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a> <a href="#L-2"> 2</a> <a href="#L-3"> 3</a> <a href="#L-4"> 4</a> <a href="#L-5"> 5</a> <a href="#L-6"> 6</a> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a> <a href="#L-11">11</a> <a href="#L-12">12</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="kn">from</span> <span class="nn">PyQt4.QtCore</span> <span class="kn">import</span> <span class="o">*</span> </span><span id="L-2"><a name="L-2"></a><span class="kn">from</span> <span class="nn">PyQt4.QtGui</span> <span class="kn">import</span> <span class="o">*</span> </span><span id="L-3"><a name="L-3"></a><span class="kn">from</span> <span class="nn">PyQt4.QtWebKit</span> <span class="kn">import</span> <span class="o">*</span> </span><span id="L-4"><a name="L-4"></a> </span><span id="L-5"><a name="L-5"></a><span class="n">myWebKit</span> <span class="o">=</span> <span class="n">QWebView</span><span class="p">()</span> </span><span id="L-6"><a name="L-6"></a><span class="n">myWebKit</span><span class="o">.</span><span class="n">show</span><span class="p">()</span> </span><span id="L-7"><a name="L-7"></a> </span><span id="L-8"><a name="L-8"></a><span class="n">myWebKit</span><span class="o">.</span><span class="n">setUrl</span><span class="p">(</span><span class="n">QUrl</span><span class="p">(</span><span class="s">&quot;http://www.google.com&quot;</span><span class="p">))</span> </span><span id="L-9"><a name="L-9"></a> </span><span id="L-10"><a name="L-10"></a><span class="n">myWebKit</span><span class="o">.</span><span class="n">page</span><span class="p">()</span><span class="o">.</span><span class="n">mainFrame</span><span class="p">()</span><span class="o">.</span><span class="n">evaluateJavaScript</span><span class="p">(</span><span class="nb">open</span><span class="p">(</span><span class="s">&#39;jquery.js&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">read</span><span class="p">())</span> </span><span id="L-11"><a name="L-11"></a> </span><span id="L-12"><a name="L-12"></a><span class="n">myWebKit</span><span class="o">.</span><span class="n">page</span><span class="p">()</span><span class="o">.</span><span class="n">mainFrame</span><span class="p">()</span><span class="o">.</span><span class="n">evaluateJavaScript</span><span class="p">(</span><span class="s">&quot;&quot;&quot;$(document).ready(function() { $(&quot;body&quot;).css(&quot;background&quot;, &quot;#f00&quot;);});&quot;&quot;&quot;</span><span class="p">)</span> </span></pre></div> </td></tr></table>
javascript, pyqt, pyqt4, python, qt