<?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>蓝色的华 &#187; pyqt4</title>
	<atom:link href="http://bluehua.org/tag/pyqt4/feed" rel="self" type="application/rss+xml" />
	<link>http://bluehua.org</link>
	<description>分享所学,backup一切~</description>
	<lastBuildDate>Fri, 13 Apr 2012 14:08:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>使用phantomjs抓取ITC和android market的安装统计数据</title>
		<link>http://bluehua.org/2011/09/14/1682.html</link>
		<comments>http://bluehua.org/2011/09/14/1682.html#comments</comments>
		<pubDate>Wed, 14 Sep 2011 06:57:44 +0000</pubDate>
		<dc:creator>冥王星2011</dc:creator>
				<category><![CDATA[IOS]]></category>
		<category><![CDATA[soft]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[phantomjs]]></category>
		<category><![CDATA[pyqt4]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=1682</guid>
		<description><![CDATA[同事用python抓各大andriod市场的页面分析软件下载量，发现andriod　market的数据是通过ajax加载的，而且貌似加密过了，没法直接解析。后来俺发现了phantomjs这个命令行的webkit,在可以在命令行渲染网页，这样不论数据怎么加载，怎么加密，对于标准的浏览器都无能为力了。软件的原理跟以前介绍的一个命令行web截图工具一样,内嵌一个qt4的webkit，然后渲染到xvfb虚拟出的xserver上。不同是这个提供了js的api，用起来方便，可以用来做爬虫，站点监控，服务端截图。 使用方法： 第一步,安装phantomjs Mac os &#038; windows: 直接下载.dmg或.exe安装包即可:http://code.google.com/p/phantomjs/downloads/list mac下安装完闭，可执行文件的路径:/Applications/phantomjs.app/Contents/MacOS/phantomjs ubuntu: sudo add-apt-repository ppa:jerome-etienne/neoip sudo apt-get update sudo apt-get install phantomjs centos 5.3: 折腾开始了。。由于phantomjs的linux版本是通过pyqt4实现的，所以装起来比较麻烦 首先我们需要安装qt4.7.而yum默认安装的是4.1 rpm -ivh http://software.freivald.com/centos/software.freivald.com-1.0.0-1.noarch.rpm yum update fontconfig fontconfig-devel yum install qt4 qt4-devel #如果已经安装过qt4则执行 yum update qt4 qt4-devel 安装Xvfb yum install xorg-x11-server-Xvfb xorg-x11-server-Xorg xorg-x11-fonts* 安装python 2.7,自带的为2.4，没法用 wget http://python.org/ftp/python/2.7.2/Python-2.7.2.tar.bz2 tar jxvf Python-2.7.2.tar.bz2 cd Python-2.7.2 [...]]]></description>
			<content:encoded><![CDATA[<p>同事用python抓各大andriod市场的页面分析软件下载量，发现andriod　market的数据是通过ajax加载的，而且貌似加密过了，没法直接解析。后来俺发现了phantomjs这个命令行的webkit,在可以在命令行渲染网页，这样不论数据怎么加载，怎么加密，对于标准的浏览器都无能为力了。软件的原理跟以前介绍的一个<a href="http://bluehua.org/2010/07/23/1397.html">命令行web截图工具</a>一样,内嵌一个qt4的webkit，然后渲染到xvfb虚拟出的xserver上。不同是这个提供了js的api，用起来方便，可以用来做爬虫，站点监控，服务端截图。</p>
<p>使用方法：<br />
第一步,安装phantomjs<br />
Mac os &#038; windows:<br />
直接下载.dmg或.exe安装包即可:<a href="http://code.google.com/p/phantomjs/downloads/list">http://code.google.com/p/phantomjs/downloads/list</a><br />
mac下安装完闭，可执行文件的路径:/Applications/phantomjs.app/Contents/MacOS/phantomjs<br />
ubuntu:</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> add-apt-repository ppa:jerome-etienne<span style="color: #000000; font-weight: bold;">/</span>neoip
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> update
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> phantomjs</pre></div></div>

<p>centos 5.3:<br />
折腾开始了。。由于phantomjs的linux版本是通过pyqt4实现的，所以装起来比较麻烦<br />
首先我们需要安装qt4.7.而yum默认安装的是4.1</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;">rpm <span style="color: #660033;">-ivh</span> http:<span style="color: #000000; font-weight: bold;">//</span>software.freivald.com<span style="color: #000000; font-weight: bold;">/</span>centos<span style="color: #000000; font-weight: bold;">/</span>software.freivald.com-1.0.0-1.noarch.rpm
yum update fontconfig fontconfig-devel
yum <span style="color: #c20cb9; font-weight: bold;">install</span> qt4 qt4-devel
<span style="color: #666666; font-style: italic;">#如果已经安装过qt4则执行 yum update qt4 qt4-devel</span></pre></div></div>

<p>安装Xvfb</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;">yum <span style="color: #c20cb9; font-weight: bold;">install</span> xorg-x11-server-Xvfb xorg-x11-server-Xorg xorg-x11-fonts<span style="color: #000000; font-weight: bold;">*</span></pre></div></div>

<p>安装python 2.7,自带的为2.4，没法用</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>python.org<span style="color: #000000; font-weight: bold;">/</span>ftp<span style="color: #000000; font-weight: bold;">/</span>python<span style="color: #000000; font-weight: bold;">/</span>2.7.2<span style="color: #000000; font-weight: bold;">/</span>Python-2.7.2.tar.bz2
<span style="color: #c20cb9; font-weight: bold;">tar</span> jxvf Python-2.7.2.tar.bz2
<span style="color: #7a0874; font-weight: bold;">cd</span> Python-2.7.2
.<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>python27
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ..</pre></div></div>

<p>安装setup tools</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>pypi.python.org<span style="color: #000000; font-weight: bold;">/</span>packages<span style="color: #000000; font-weight: bold;">/</span>source<span style="color: #000000; font-weight: bold;">/</span>s<span style="color: #000000; font-weight: bold;">/</span>setuptools<span style="color: #000000; font-weight: bold;">/</span>setuptools-0.6c11.tar.gz<span style="color: #666666; font-style: italic;">#md5=7df2a529a074f613b509fb44feefe74e</span>
<span style="color: #c20cb9; font-weight: bold;">tar</span> zxvf setuptools-0.6c11.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> setuptools-0.6c11
<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>python27<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>python setup.py <span style="color: #c20cb9; font-weight: bold;">install</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ..</pre></div></div>

<p>安装sip</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.riverbankcomputing.com<span style="color: #000000; font-weight: bold;">/</span>static<span style="color: #000000; font-weight: bold;">/</span>Downloads<span style="color: #000000; font-weight: bold;">/</span>sip4<span style="color: #000000; font-weight: bold;">/</span>sip-4.12.4.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> zxvf sip-4.12.4.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> sip-4.12.4
<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>python27<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>python configure.py
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ..</pre></div></div>

<p>安装pyqt4</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>www.riverbankcomputing.com<span style="color: #000000; font-weight: bold;">/</span>static<span style="color: #000000; font-weight: bold;">/</span>Downloads<span style="color: #000000; font-weight: bold;">/</span>PyQt4<span style="color: #000000; font-weight: bold;">/</span>PyQt-x11-gpl-4.8.5.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> zxvf PyQt-x11-gpl-4.8.5.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> PyQt-x11-gpl-4.8.5
<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>python27<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>python configure.py <span style="color: #660033;">-q</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>qt4<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>qmake
<span style="color: #666666; font-style: italic;">#对于64位系统</span>
<span style="color: #666666; font-style: italic;">#/opt/python27/bin/python configure.py -q /usr/lib64/qt4/bin/qmake</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> 
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> ..</pre></div></div>

<p>最后安装pyphantomjs</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> pyphantomjs
<span style="color: #7a0874; font-weight: bold;">cd</span> pyphantomjs
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>phantomjs.googlecode.com<span style="color: #000000; font-weight: bold;">/</span>files<span style="color: #000000; font-weight: bold;">/</span>pyphantomjs-1.2.0-source.zip
<span style="color: #c20cb9; font-weight: bold;">unzip</span> pyphantomjs-1.2.0-source.zip
<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>python27<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>python setup.py <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>折腾到这里，pyphantomjs已经安装到了/opt/python27/bin/pyphantomjs<br />
直接执行/opt/python27/bin/pyphantomjs &#8211;help,会发现报错</p>
<pre>
sip.setapi('QString', 2)
ValueError: API 'QString' has already been set to version 1
</pre>
<p>解决方法<br />
编辑/opt/python27/bin/pyphantomjs,在开始追加几句</p>

<div class="wp_syntax"><div class="code overflow"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/opt/python27/bin/python</span>
<span style="color: #808080; font-style: italic;"># EASY-INSTALL-ENTRY-SCRIPT: 'PyPhantomJS==1.2.0','console_scripts','pyphantomjs'</span>
<span style="color: #808080; font-style: italic;">#fix start</span>
<span style="color: #ff7700;font-weight:bold;">import</span> sip
sip.<span style="color: black;">setapi</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'QString'</span>, <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>
sip.<span style="color: black;">setapi</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'QVariant'</span>, <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span>
<span style="color: #808080; font-style: italic;">#fix end</span>
__requires__ = <span style="color: #483d8b;">'PyPhantomJS==1.2.0'</span></pre></div></div>

<p>第二步：<br />
下载我们用来解析数据的js脚本:<a href='http://bluehua.org/wp-content/uploads/2011/09/android_itc_daliy_report.zip'>android_itc_daliy_report</a></p>
<p>修改里面的变量:</p>
<pre>
TIMEOUT = 120;//脚本执行超时时间
ACCOUNT = '';//登陆账号
PASSWORD = '';//密码
</pre>
<p>第三步:执行抓取脚本<br />
对于Mac os:</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#抓取andriod market的安装总量</span>
<span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>phantomjs.app<span style="color: #000000; font-weight: bold;">/</span>Contents<span style="color: #000000; font-weight: bold;">/</span>MacOS<span style="color: #000000; font-weight: bold;">/</span>phantomjs <span style="color: #660033;">--load-images</span>=no AndroidMarketDailyReport.js
<span style="color: #666666; font-style: italic;">#抓取ITC的每天的安装量,需要制定日期，而且日期必须是web页面里的日期选择框里有的日期</span>
<span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>phantomjs.app<span style="color: #000000; font-weight: bold;">/</span>Contents<span style="color: #000000; font-weight: bold;">/</span>MacOS<span style="color: #000000; font-weight: bold;">/</span>phantomjs <span style="color: #660033;">--load-images</span>=no ITCDailyReport.js 09<span style="color: #000000; font-weight: bold;">/</span>06<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2011</span></pre></div></div>

<p>对于Centos:</p>

<div class="wp_syntax"><div class="code overflow"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#首先保证Xvfb已经启动</span>
Xvfb :<span style="color: #000000;">0</span> <span style="color: #660033;">-screen</span> <span style="color: #000000;">0</span> 1024x768x24 <span style="color: #000000; font-weight: bold;">&amp;</span>
<span style="color: #666666; font-style: italic;">#抓取andriod market的安装量</span>
<span style="color: #007800;">DISPLAY</span>=:<span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>python27<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pyphantomjs <span style="color: #660033;">--load-images</span>=no <span style="color: #660033;">--ignore-ssl-errors</span>=<span style="color: #c20cb9; font-weight: bold;">yes</span> AndroidMarketDailyReport.js
<span style="color: #666666; font-style: italic;">#抓取ITC的每天的安装量,需要制定日期，而且日期必须是web页面里的日期选择框里有的日期</span>
<span style="color: #007800;">DISPLAY</span>=:<span style="color: #000000;">0</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>python27<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>pyphantomjs <span style="color: #660033;">--load-images</span>=no <span style="color: #660033;">--ignore-ssl-errors</span>=<span style="color: #c20cb9; font-weight: bold;">yes</span> ITCDailyReport.js 09<span style="color: #000000; font-weight: bold;">/</span>06<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2011</span></pre></div></div>

<p>获取输出结果,以Mac os为例:</p>
<p>/Applications/phantomjs.app/Contents/MacOS/phantomjs &#8211;load-images=no ITCDailyReport.js 09/06/2011|grep REPORT<br />
REPORT:	soft_name	0000<br />
REPORT:	soft_name	0000</p>
<p>/Applications/phantomjs.app/Contents/MacOS/phantomjs &#8211;load-images=no AndroidMarketDailyReport.js |grep REPORT<br />
REPORT:	total	0000<br />
REPORT:	real	0000</p>
<p>如果没有输出结果，则说明有异常，账号错误，超时，等等。。</p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2011/09/14/1682.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>准备做一个wordpress的离线编辑器</title>
		<link>http://bluehua.org/2010/01/24/886.html</link>
		<comments>http://bluehua.org/2010/01/24/886.html#comments</comments>
		<pubDate>Sun, 24 Jan 2010 07:47:26 +0000</pubDate>
		<dc:creator>冥王星2011</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[soft]]></category>
		<category><![CDATA[offline editor]]></category>
		<category><![CDATA[pyqt4]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://bluehua.org/?p=886</guid>
		<description><![CDATA[2010.3.6 更新 由于最近的学习充电计划,这个东西暂时搁置了,现在已经可以自动保存了~ &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212; linux平台上一直没有这样一个所见即所得的blog离线编辑器,昨天试着用pyqt4写了一个小脚本,发现原来python做客户端软件是如此容易.然后下定决心要利用n个周末的时间自己写一个. 开始打算用纯qt的ui控件实现,但是感觉没有wordpress的编辑器这么亲切,于是想到一个界面亲切,实现也方便的方案: ui部分直接用web,框在一个pyqt的webkit组件里,逻辑部分用python的cgihttpserver在本地开一个cgi. 这个东西搞到今天雏形已经有了,可以实现跟wordress完全相同的书写体验. 顺带发那个pyqt的练手之作 :　emlreader.py 一个可以查看eml附件的脚本]]></description>
			<content:encoded><![CDATA[<p>2010.3.6 更新<br />
由于最近的学习充电计划,这个东西暂时搁置了,现在已经可以自动保存了~<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br />
linux平台上一直没有这样一个所见即所得的blog离线编辑器,昨天试着用pyqt4写了一个小脚本,发现原来python做客户端软件是如此容易.然后下定决心要利用n个周末的时间自己写一个.</p>
<p>开始打算用纯qt的ui控件实现,但是感觉没有wordpress的编辑器这么亲切,于是想到一个界面亲切,实现也方便的方案: ui部分直接用web,框在一个pyqt的webkit组件里,逻辑部分用python的cgihttpserver在本地开一个cgi.</p>
<p>这个东西搞到今天雏形已经有了,可以实现跟wordress完全相同的书写体验.</p>
<p><a href="http://bluehua.org/wp-content/uploads/2010/01/screenshot_048.png"><img class="alignnone size-medium wp-image-887" title="screenshot_048" src="http://bluehua.org/wp-content/uploads/2010/01/screenshot_048-300x240.png" alt="" width="300" height="240" /></a></p>
<p>顺带发那个pyqt的练手之作 :　<a href="http://bluehua.org/wp-content/uploads/2010/01/emlreader.py_.zip">emlreader.py</a> 一个可以查看eml附件的脚本</p>
]]></content:encoded>
			<wfw:commentRss>http://bluehua.org/2010/01/24/886.html/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.593 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-05-22 09:15:16 -->

