<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>a Display of Patience &#187; javascript</title>
	<atom:link href="http://www.displayofpatience.net/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.displayofpatience.net</link>
	<description>my favorite patient</description>
	<lastBuildDate>Sun, 18 Apr 2010 07:34:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Reading ajax content programmatically</title>
		<link>http://www.displayofpatience.net/2009/10/reading-ajax-content-programmatically/</link>
		<comments>http://www.displayofpatience.net/2009/10/reading-ajax-content-programmatically/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 21:44:47 +0000</pubDate>
		<dc:creator>bodhi</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[sw development]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[PyQt4]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.displayofpatience.net/?p=196</guid>
		<description><![CDATA[Javascript and dynamic content loading with Ajax has changed the way web is being used. User interfaces have advanced rapidly and the &#8220;web content&#8221; is becoming more and more complex. This, however, presents whole new kinds of problems for parties other than the expected end user. Web content is intended to be read with a [...]]]></description>
			<content:encoded><![CDATA[<p>Javascript and dynamic content loading with Ajax has changed the way web is being used. User interfaces have advanced rapidly and the &#8220;web content&#8221; is becoming more and more complex. This, however, presents whole new kinds of problems for parties other than the expected end user. Web content is intended to be read with a graphical browser, such as Firefox or Google Chrome. Javascript capabilities are taken for granded, as they should, as we live in the modern ages <img src='http://www.displayofpatience.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  However, sometimes there still is a need for reading the content programmatically. Ajax content loading can become quite a pain in the ass in such situations, as I now have learnt.</p>
<p>In most cases, content retrieved by Ajax after the normal page is being loaded, isn&#8217;t a problem. If you really need the content, you can usually see how the Ajax call is made and use the same url for getting the data directly. In Most Cases. Sometimes the Ajax calls are not so obvious; the javascript might be obfuscated or you can&#8217;t really tell where the data is being loaded from. Or sometimes you just need to simulate the actual page loading. Test automation could be one of such situation. None the less, the problem is loading the actual data. Before Ajax-times, you could just use wget, or maybe a library provided by your programming language of choice (Python &#8211; urllib2) &#8211; to fetch the HTML source. Javascript changed this, as almost nothing, except the actual web browers, can execute it while reading the source.</p>
<p>Few days ago I faced such a problem. I spent most of my day figuring out how to read Javascript-rich web 2.0 page content using only tools available in shell environment. I preferred something I could use with Python, but nothing seemed to work. As I had almost lost all hope of achieving my goal, I decided to take one last look of PyQt4. I knew QT had a webkit component but I didn&#8217;t know if it can be used in a non graphical environemnt or if PyQt4 supported it. It can but it cannot and it does but it does not&#8230;</p>
<p>When I first tried PyQt4 it seemed to include WebKit module. But it didn&#8217;t. After a long session of banging my head against the wall I realized that even though the module QtWebKit was there, it didn&#8217;t actually do anything. It just failed silently when I used it. Then I came across this: <a href="http://www.insecure.ws/2008/09/16/xserver-less-webpage-screenshot#comment-239">http://www.insecure.ws/2008/09/16/xserver-less-webpage-screenshot#comment-239</a>. It seems version 4.4.2 of PyQt4 is sometimes build without support of WebKit. Guess which version I was using? I updated my PyQt and got immediately some results.  I also found out that QWebPage can be used in a widgetless situation. I also learnt that PyQt crashes when you create such object without first starting QtGui app by: QtGui.QApplication(sys.argv). It doesn&#8217;t work if you pass the second argument as False, for starting a non-Gui QT application. This seemed like a deal breaker to me, even though I was able to render the complex html with ajax calls just correctly with all the data included. It bugged the hell out of me. I drew no windows, no dialogs, nothing graphical. And yes, you cannot run a PyQt GUI application in shell, even though it produces no graphics. There was no physical QWebPage to be seen, everything happened on the background, why the hell it didn&#8217;t work as non Gui Qt Application? I never found an answer for this, but I found a way around it: XVFB, thanks to <a href="http://www.insecure.ws/2008/09/16/xserver-less-webpage-screenshot">the post</a> I referenced earlier.</p>
<p>Xvfb is a Virtual Framebuffer for X. What a life saver. I don&#8217;t know how it does it what it does, but basically it fakes a Display in linux environment where X is not available. I guess it directs everything to /dev/null or something, which in my case was just perfect, as I didn&#8217;t even want to produce anything graphical. My only interest was the HTML content, in textual format. So now, with the help of Xvfb, I can run &#8220;graphical programs&#8221; in shell and render my complex web pages programmatically, and parse the results as I please. Maybe my solution is not perfect and maybe there is some cleaner way of doing it, but I couldn&#8217;t find it. If you know, please share! Until that, I&#8217;m quite happy running my PyQt application (even though it seems to be quite heavy for such a basic task).</p>
<p>After I gave PyQt a shot, I did some googling and found out that others have used the same approach as me. Here&#8217;s one link:</p>
<p><a href="http://aezell.wordpress.com/2009/02/13/screenshot-a-url-with-python-and-qt-and-webkit/">http://aezell.wordpress.com/2009/02/13/screenshot-a-url-with-python-and-qt-and-webkit/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.displayofpatience.net/2009/10/reading-ajax-content-programmatically/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Simple example of Django on shared host</title>
		<link>http://www.displayofpatience.net/2009/10/simple-example-of-django-on-shared-host/</link>
		<comments>http://www.displayofpatience.net/2009/10/simple-example-of-django-on-shared-host/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 18:57:39 +0000</pubDate>
		<dc:creator>bodhi</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[sw development]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.displayofpatience.net/?p=192</guid>
		<description><![CDATA[Displayofpatience.net runs on a shared host. It&#8217;s basically your avarage wordpress site, and the whole domain is dedicated to it. In addition to wordpress, I wanted to try if I could run a django site along with it. The first thing was to install Django. Running stuff on a shared host can be tricky. Installing [...]]]></description>
			<content:encoded><![CDATA[<p>Displayofpatience.net runs on a shared host. It&#8217;s basically your avarage wordpress site, and the whole domain is dedicated to it. In addition to wordpress, I wanted to try if I could run a django site along with it. The first thing was to install Django.</p>
<p>Running stuff on a shared host can be tricky. Installing stuff can be even trickier. My first task was to install Django. Even though my host/webhotel provided Django, I wanted to use a newer version. After digging around I found a wonderful little script for creating a virtual environemnt for Python. It basically creates bin &amp; lib (&amp; site-packages) directories to your home directory and links them to the system-wide python. Only now when you use your &#8220;local&#8221; python you can safely install stuff to the site-packages directory, using basic &#8220;setup.py install&#8221; method. It works great and you need no additional priviledges as you install everything under your home directory. Pretty cool. <a href="http://peak.telecommunity.com/DevCenter/EasyInstall#creating-a-virtual-python">Check out more information about virtual-python here</a>.</p>
<p>After installing Django I was ready to try to set up a live site using it. I didn&#8217;t have any real needs for my Django site, so I decided to just hack something up, that demonstrates that I can use Django on my shared host. Displayofpatience.net runs on Apache, so I figured fcgi was the way to go. I created a .fcgi script according Django documentation and it worked out of the box. I, of course, used my own &#8220;local&#8221; python for running the fcgi script. Then I just configured  .htaccess file to handle .fcgi files (all in the Django docs). Django takes care from that on, according to the project urls.py.</p>
<p><a href="http://www.displayofpatience.net/django/lotto/">Here is the outcome: The awesome Lottery machine!</a></p>
<p>To spice things up a little, I also added some JQuery ajax and animations to my program.  I hadn&#8217;t tried JQuery before, so that too was also a nice learning experience. I&#8217;m really happy about the outcome. Of course, the actual program is pretty useless, but now I can run my wordpress site as usually and Django applications along with it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.displayofpatience.net/2009/10/simple-example-of-django-on-shared-host/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
