<?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>juust ~ php oddities &#187; google</title>
	<atom:link href="http://www.juust.org/index.php/tag/google/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.juust.org</link>
	<description>Link theory and search engine optimization</description>
	<lastBuildDate>Thu, 19 Jan 2012 09:39:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>contact us</title>
		<link>http://www.juust.org/index.php/contact-us/2012/01/</link>
		<comments>http://www.juust.org/index.php/contact-us/2012/01/#comments</comments>
		<pubDate>Sat, 31 Dec 2011 22:39:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://www.juust.org/?p=2092</guid>
		<description><![CDATA[I read somewhere on BHW that Google have 25 billion pages indexed. Whilst scr*ping I wondered how many pages the phrase &#8216;contact us&#8217; has, so I checked it and it has 5 billion. Then I saw the serp in Google &#8230; <a href="http://www.juust.org/index.php/contact-us/2012/01/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I read somewhere on BHW that Google have 25 billion pages indexed. Whilst scr*ping I wondered how many pages the phrase &#8216;contact us&#8217; has, so I checked it and it has 5 billion. Then I saw the serp in Google where right above the White House and Google is the Boston Herald page. </p>
<div id="attachment_2093" class="wp-caption alignright" style="width: 818px"><a href="http://www.juust.org/wp-content/uploads/2012/01/contact-us-google.png" rel="shadowbox[post-2092];player=img;"><img class="size-full wp-image-2093" title="contact us google" src="http://www.juust.org/wp-content/uploads/2012/01/contact-us-google.png" alt="contact us google" width="808" height="629" /></a><p class="wp-caption-text">contact us google</p></div>
<p>I really wonder how Matt and company figure that one in terms of relevance to the query.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.juust.org/index.php/contact-us/2012/01/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>google suggest scraper (php &amp; simplexml)</title>
		<link>http://www.juust.org/index.php/google-suggest-scraper-php-simplexml/2011/12/</link>
		<comments>http://www.juust.org/index.php/google-suggest-scraper-php-simplexml/2011/12/#comments</comments>
		<pubDate>Mon, 19 Dec 2011 00:08:12 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[google]]></category>
		<category><![CDATA[seo tips and tricks]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[scrape]]></category>
		<category><![CDATA[simplexml]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://www.juust.org/?p=1834</guid>
		<description><![CDATA[Today&#8217;s goal is a basic php Google Suggest scraper because I wanted traffic data and keywords for free. Before we start : google scraping is bad ! Good People use the Google Adwords API : 25 cents for 1000 units, &#8230; <a href="http://www.juust.org/index.php/google-suggest-scraper-php-simplexml/2011/12/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today&#8217;s goal is a basic php Google Suggest scraper because I wanted traffic data and keywords for free.</p>
<p>Before we start :</p>
<h2 style="text-align: center;">google scraping is <strong>bad</strong> !</h2>
<p>Good People use the <a title="google adwords api" href="http://code.google.com/apis/adwords/">Google Adwords API</a> : 25 cents for 1000 units, 15++ units for keyword suggestion so they pay 4 or 5 dollar for 1000 keyword suggestions (if they can find a good programmer which also costs a few dollars). Or they opt for <a title="search engine marketing data" href="http://www.semrush.com" rel="nofollow">SemRush</a> (also my preference), <a href="http://www.keywordspy.com" rel="nofollow">KeywordSpy</a>, <a href="http://www.spyfu.com" rel="nofollow">Spyfu</a>, and other services like 7Search PPC programs to get keyword and traffic data and data on their competitors but these also charge about 80 dollars per month for a limited account up to a few hundred per month for seo companies. Good people pay plenty.</p>
<p>We tiny grey webmice of marketing however just want a few estimates, at low or better no cost : like this :</p>
<table width="276" border="0" cellspacing="0" cellpadding="0">
<colgroup>
<col width="206" />
<col width="70" /> </colgroup>
<tbody>
<tr>
<td width="206" height="20">data</td>
<td align="right" width="70">num queries</td>
</tr>
<tr>
<td width="206" height="20">google suggest</td>
<td align="right" width="70">57800000</td>
</tr>
<tr>
<td height="20">google suggestion box</td>
<td align="right">5390000</td>
</tr>
<tr>
<td height="20">google suggest api</td>
<td align="right">5030000</td>
</tr>
<tr>
<td height="20">google suggestion tool</td>
<td align="right">3670000</td>
</tr>
<tr>
<td height="20">google suggest a site</td>
<td align="right">72700000</td>
</tr>
<tr>
<td height="20">google suggested users</td>
<td align="right">57000000</td>
</tr>
<tr>
<td height="20">google suggestions funny</td>
<td align="right">37400000</td>
</tr>
<tr>
<td height="20"><strong>google suggest scraper</strong></td>
<td align="right">62800</td>
</tr>
<tr>
<td height="20">google suggestions not working</td>
<td align="right">87100000</td>
</tr>
<tr>
<td height="20">google suggested user list</td>
<td align="right">254000000</td>
</tr>
</tbody>
</table>
<p>Suggestion autocomplete is AJAX, it outputs XML :</p>
<pre>&lt; ?xml version="1.0"? &gt;
   &lt;toplevel&gt;
     &lt;CompleteSuggestion&gt;
       &lt;suggestion data="senior quotes"/&gt;
       &lt;num_queries int="30000000"/&gt;
     &lt;/CompleteSuggestion&gt;
     &lt;CompleteSuggestion&gt;
       &lt;suggestion data="senior skip day lyrics"/&gt;
       &lt;num_queries int="441000"/&gt;
     &lt;/CompleteSuggestion&gt;
   &lt;/toplevel&gt;</pre>
<p>Using SimpleXML, the PHP routine is as simple as querying <strong><em>g00gle.c0m/complete/search?</em></strong>, grabbing the autocomplete xml, and extracting the attribute data :</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re1">$_SERVER</span><span class="br0">&#91;</span><span class="st0">&#39;QUERY_STRING&#39;</span><span class="br0">&#93;</span><span class="sy0">==</span><span class="st0">&#39;&#39;</span><span class="br0">&#41;</span> <span class="kw3">die</span><span class="br0">&#40;</span><span class="st0">&#39;enter a query like http://host/filename.php?query&#39;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$contentstring</span> <span class="sy0">=</span> <span class="sy0">@</span><span class="kw3">file_get_contents</span><span class="br0">&#40;</span><span class="st0">&quot;http://g00gle.c0m/complete/search?output=toolbar&amp;amp;q=&quot;</span><span class="sy0">.</span><span class="kw3">urlencode</span><span class="br0">&#40;</span><span class="re1">$kw</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span> &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="re1">$content</span> <span class="sy0">=</span> simplexml_load_string<span class="br0">&#40;</span><span class="re1">$contentstring</span> <span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$content</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>CompleteSuggestion <span class="kw1">as</span> <span class="re1">$c</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$term</span> <span class="sy0">=</span> <span class="br0">&#40;</span>string<span class="br0">&#41;</span> <span class="re1">$c</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>suggestion<span class="sy0">-&amp;</span>gt<span class="sy0">;</span>attributes<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>data<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//note : traffic data is sometimes missing &nbsp; </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re1">$traffic</span> <span class="sy0">=</span> <span class="br0">&#40;</span>string<span class="br0">&#41;</span> <span class="re1">$c</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>num_queries<span class="sy0">-&amp;</span>gt<span class="sy0">;</span>attributes<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">-&amp;</span>gt<span class="sy0">;</span>int<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">echo</span> <span class="re1">$term</span><span class="sy0">.</span> <span class="st0">&quot; &quot;</span><span class="sy0">.</span><span class="re1">$traffic</span> <span class="sy0">.</span> <span class="st0">&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="st0">&quot;</span> <span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>I made a quick php script that outputs the terms as a list of new queries so you can walk through the suggestions :</p>
<p><a href="http://www.juust.org/wp-content/uploads/2011/12/google-suggest-scraper-tool.jpg" rel="shadowbox[post-1834];player=img;"><img class="alignnone size-medium wp-image-1835" title="google suggest scraper tool" src="http://www.juust.org/wp-content/uploads/2011/12/google-suggest-scraper-tool-300x289.jpg" alt="" width="529" height="400" /></a></p>
<p><a href="http://www.juust.org/wp-content/uploads/2011/12/google-suggest-scraper-tool-II1.jpg" rel="shadowbox[post-1834];player=img;"><img class="alignnone size-medium wp-image-1837" title="google suggest scraper tool II" src="http://www.juust.org/wp-content/uploads/2011/12/google-suggest-scraper-tool-II1-300x286.jpg" alt="" width="462" height="440" /></a></p>
<p>The source is as text file up for <a title="google suggest scraper tool code" href="http://www.juust.org/suggestit.txt">download overhere</a> (rename it to suggestit.php and it should run on any server with php5.* and simplexml).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.juust.org/index.php/google-suggest-scraper-php-simplexml/2011/12/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ga api sample : get pageviews</title>
		<link>http://www.juust.org/index.php/google-analytics-api-sample-get-pageviews/2009/05/</link>
		<comments>http://www.juust.org/index.php/google-analytics-api-sample-get-pageviews/2009/05/#comments</comments>
		<pubDate>Wed, 13 May 2009 14:58:01 +0000</pubDate>
		<dc:creator>juust</dc:creator>
				<category><![CDATA[google]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[ga]]></category>
		<category><![CDATA[namespaces]]></category>
		<category><![CDATA[simplexml]]></category>

		<guid isPermaLink="false">http://www.juust.org/?p=504</guid>
		<description><![CDATA[I was going to put that online : how to get the pageviews out of the google analytics api, using simplexml and php. Google use three namespaces in the output file which make it less easy accessible, so here&#8217;s a &#8230; <a href="http://www.juust.org/index.php/google-analytics-api-sample-get-pageviews/2009/05/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was going to put that online : how to get the pageviews out of the google analytics api, using simplexml and php. Google use three namespaces in the output file which make it less easy accessible, so here&#8217;s a quick sample of how to get your sites pageviews out of it :</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="co1">//ids &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = site identifier (from the site data feed)</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//metrics &nbsp; &nbsp; = what i want to see</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//start-date </span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//end-date </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$feedUri</span> <span class="sy0">=</span> <span class="st0">&quot;https://www.google.com/analytics/feeds/data?ids=ga:10516419&amp;metrics=ga:pageviews&amp;start-date=2009-04-01&amp;end-date=2009-05-01&quot;</span><span class="sy0">;</span> &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$curl</span> <span class="sy0">=</span> curl_init<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_URL<span class="sy0">,</span> <span class="re1">$feedUri</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_CONNECTTIMEOUT<span class="sy0">,</span> <span class="nu0">3</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_RETURNTRANSFER<span class="sy0">,</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp;<span class="re1">$headers</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st0">&quot;Authorization: GoogleLogin auth=&quot;</span><span class="sy0">.</span><span class="re1">$Authtoken</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//for authtoken : see previous post</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_HTTPHEADER<span class="sy0">,</span> <span class="re1">$headers</span><span class="br0">&#41;</span><span class="sy0">;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp;curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_SSL_VERIFYHOST<span class="sy0">,</span> <span class="nu0">0</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_SSL_VERIFYPEER<span class="sy0">,</span> <span class="kw2">false</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_VERBOSE<span class="sy0">,</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//get the string containing the xml file</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$gA</span> <span class="sy0">=</span> curl_exec<span class="br0">&#40;</span><span class="re1">$curl</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p>the feed has three namespaces (atom, opensearch and dxp/analytics), a simple way is accessing the ENTRY tags (from the Atom namespace), in that tag is one DXP: line and that has the answer to the question.</p>
<p>&lt;dxp:metric confidenceInterval=&#8217;0.0&#8242; name=&#8217;ga:pageviews&#8217; type=&#8217;integer&#8217; value=&#8217;755&#8242;/&gt;</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="co1">//load the string into a simple xml object</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$feed</span> <span class="sy0">=</span> simplexml_load_string<span class="br0">&#40;</span><span class="re1">$gA</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//take the atom namespace</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$children</span> <span class="sy0">=</span> &nbsp;<span class="re1">$feed</span><span class="sy0">-&gt;</span><span class="me1">children</span><span class="br0">&#40;</span><span class="st0">&#39;http://www.w3.org/2005/Atom&#39;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//take the entry tags</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$parts</span> <span class="sy0">=</span> <span class="re1">$children</span><span class="sy0">-&gt;</span><span class="me1">entry</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">foreach</span> <span class="br0">&#40;</span><span class="re1">$parts</span> <span class="kw1">as</span> <span class="re1">$entry</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//from the entry tag,</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//access the dxp namespace</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re1">$dxp</span> <span class="sy0">=</span> <span class="br0">&#40;</span>object<span class="br0">&#41;</span> <span class="re1">$entry</span><span class="sy0">-&gt;</span><span class="me1">children</span><span class="br0">&#40;</span><span class="st0">&#39;http://schemas.google.com/analytics/2009&#39;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//METRIC contains the answer to the question</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//grab from the tag METRIC the attribute VALUE</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">echo</span> &nbsp; <span class="br0">&#40;</span>string<span class="br0">&#41;</span> <span class="re1">$dxp</span><span class="sy0">-&gt;</span><span class="me1">metric</span><span class="sy0">-&gt;</span><span class="me1">attributes</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">-&gt;</span><span class="me1">value</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Important is using the (string) typecast, normally simplexml returns a simplexml object, when you force a string type, it gives the actual metric ga:pageview <strong>value</strong> attribute as number.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.juust.org/index.php/google-analytics-api-sample-get-pageviews/2009/05/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>google analytics have an api !</title>
		<link>http://www.juust.org/index.php/google-analytics-api-with-php-curl/2009/05/</link>
		<comments>http://www.juust.org/index.php/google-analytics-api-with-php-curl/2009/05/#comments</comments>
		<pubDate>Mon, 11 May 2009 17:32:52 +0000</pubDate>
		<dc:creator>juust</dc:creator>
				<category><![CDATA[google]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[analytics]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[ga]]></category>

		<guid isPermaLink="false">http://www.juust.org/?p=499</guid>
		<description><![CDATA[[note: over at ioncannon Carson McDonald made a cool google analytics plugin for wordpress, i use it on this blog, works fine]. An actual google analytics api, and I missed out on it. This api is already a month old &#8230; <a href="http://www.juust.org/index.php/google-analytics-api-with-php-curl/2009/05/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>[note: over at <a href="http://www.ioncannon.net/projects/google-analytics-dashboard-wordpress-widget/">ioncannon</a> Carson McDonald made a cool google analytics plugin for wordpress, i use it on this blog, works fine].</p>
<p>An actual google analytics api, and I missed out on it. This api is already a month old and i havent read anything on the blogs about it. </p>
<p>I found it half an hour ago, I havent checked it completely but it looks promising. Here is the first bit, basic authentication with php and curl.</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="re1">$USER_EMAIL</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span><span class="sy0">;</span> <span class="co1">// #Insert your Google Account email here</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$USER_PASS</span><span class="sy0">=</span><span class="st0">&quot;&quot;</span><span class="sy0">;</span> <span class="co1">//#Insert your password here</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//array with some general data</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$data</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;Email&quot;</span> <span class="sy0">=&gt;</span> <span class="re1">$USER_EMAIL</span><span class="sy0">,</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;Passwd&quot;</span> <span class="sy0">=&gt;</span> <span class="re1">$USER_PASS</span><span class="sy0">,</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;accountType&quot;</span> <span class="sy0">=&gt;</span> <span class="st0">&quot;GOOGLE&quot;</span><span class="sy0">,</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;source&quot;</span> <span class="sy0">=&gt;</span> <span class="st0">&quot;curl-accountFeed-v1&quot;</span><span class="sy0">,</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="st0">&quot;service&quot;</span> <span class="sy0">=&gt;</span> <span class="st0">&quot;analytics&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$friends_url</span> <span class="sy0">=</span> <span class="st0">&#39;https://www.google.com/accounts/ClientLogin&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$curl</span> <span class="sy0">=</span> curl_init<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_URL<span class="sy0">,</span> <span class="re1">$friends_url</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_CONNECTTIMEOUT<span class="sy0">,</span> <span class="nu0">3</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_RETURNTRANSFER<span class="sy0">,</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//http-post that contains the array as data</span></div>
</li>
<li class="li1">
<div class="de1">curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_POST<span class="sy0">,</span> <span class="kw2">true</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_POSTFIELDS<span class="sy0">,</span> <span class="re1">$data</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//go shove the https secure connection verification</span></div>
</li>
<li class="li1">
<div class="de1">curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_SSL_VERIFYHOST<span class="sy0">,</span> <span class="nu0">0</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_SSL_VERIFYPEER<span class="sy0">,</span> <span class="kw2">false</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_VERBOSE<span class="sy0">,</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$googleAuth</span> <span class="sy0">=</span> curl_exec<span class="br0">&#40;</span><span class="re1">$curl</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//optional : some feedback</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//check if we get an error code from cUrl</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// &nbsp; &nbsp;echo curl_errno($curl).&quot;&lt;br /&gt;&quot;;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// &nbsp; &nbsp;echo &nbsp;curl_error($curl).&quot;&lt;br /&gt;&quot; ;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//print the body of the returned data</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// &nbsp; &nbsp;print_r($googleAuth);</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//print all the headers</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// &nbsp; &nbsp;$info = curl_getinfo($curl);</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// &nbsp; &nbsp;print_r($info);</span></div>
</li>
</ol>
</div>
<p>somewhere in the garbled mess that curl returns is the Authorization token, starts with <strong>auth=</strong>.</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="re1">$start</span> <span class="sy0">=</span> <span class="kw3">strpos</span><span class="br0">&#40;</span><span class="re1">$googleAuth</span><span class="sy0">,</span> <span class="st0">&quot;Auth=&quot;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="nu0">5</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$Authtoken</span> <span class="sy0">=</span> <span class="kw3">substr</span><span class="br0">&#40;</span><span class="re1">$googleAuth</span><span class="sy0">,</span> <span class="re1">$start</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//echo $Authtoken;</span></div>
</li>
</ol>
</div>
<p>I put that token in the header of the next calls and google assumes  I am kosher : time to get the accounts feed  :</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="co1">//add the authoritzation token as extra header</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$headers</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="st0">&quot;Authorization: GoogleLogin auth=&quot;</span><span class="sy0">.</span><span class="re1">$Authtoken</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$friends_url</span> <span class="sy0">=</span> <span class="st0">&#39;https://www.google.com/analytics/feeds/accounts/default&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$curl</span> <span class="sy0">=</span> curl_init<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_URL<span class="sy0">,</span> <span class="re1">$friends_url</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_CONNECTTIMEOUT<span class="sy0">,</span> <span class="nu0">3</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_RETURNTRANSFER<span class="sy0">,</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_HTTPHEADER<span class="sy0">,</span> <span class="re1">$headers</span><span class="br0">&#41;</span><span class="sy0">;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp;curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_SSL_VERIFYHOST<span class="sy0">,</span> <span class="nu0">0</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_SSL_VERIFYPEER<span class="sy0">,</span> <span class="kw2">false</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;curl_setopt<span class="br0">&#40;</span><span class="re1">$curl</span><span class="sy0">,</span> CURLOPT_VERBOSE<span class="sy0">,</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$googleAccounts</span> <span class="sy0">=</span> curl_exec<span class="br0">&#40;</span><span class="re1">$curl</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//check errors</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> curl_errno<span class="br0">&#40;</span><span class="re1">$curl</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> curl_error<span class="br0">&#40;</span><span class="re1">$curl</span><span class="br0">&#41;</span> <span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">print_r</span><span class="br0">&#40;</span><span class="re1">$googleAccounts</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p>And there it is : a whole list with weird codes, my account list :) seems easier than the other gData api&#8217;s.</p>
<p>note : the <a href="http://code.google.com/p/ga-api-http-samples/source/browse/trunk/src/v1/dataFeed.sh">google code curl example</a> does not show the &#8221; auth=&#8221; part of the token, they assume you use the entire line &#8220;auth=&#8230;&#8221; as token.</p>
<p>Once I have my spectacular visitor count in a sidebar widget I&#8217;ll blog another post on this one.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.juust.org/index.php/google-analytics-api-with-php-curl/2009/05/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>the black hatling</title>
		<link>http://www.juust.org/index.php/the-black-hatling/2009/03/</link>
		<comments>http://www.juust.org/index.php/the-black-hatling/2009/03/#comments</comments>
		<pubDate>Thu, 19 Mar 2009 16:07:54 +0000</pubDate>
		<dc:creator>juust</dc:creator>
				<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://www.juust.org/?p=369</guid>
		<description><![CDATA[It was lovely summer weather in the country, and the golden corn, the green oats, and the haystacks piled up in the meadows looked beautiful. The stork walking about on his long red legs chattered in the Egyptian language, which &#8230; <a href="http://www.juust.org/index.php/the-black-hatling/2009/03/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It was lovely summer weather in the country, and the golden corn, the green oats, and the haystacks piled up in the meadows looked beautiful. The stork walking about on his long red legs chattered in the Egyptian language, which he had learnt from his mother. The corn-fields and meadows were surrounded by large forests, in the midst of which were deep pools. </p>
<p>It was, indeed, delightful to walk about in the country. In a sunny spot stood a pleasant old forum close by a portal, and from the forum down to the web grew great landing pages, so tall, that under the tallest of them a little child could stand upright. In this snug retreat sat a white-hat on her nest, watching for her young brood to hatch; she was beginning to get tired of her task, for the little ones were a long time coming out of their shells, and she seldom had any visitors. The other white-hats liked much better to surf about in the seomoz than to climb the slippery banks, and have a gossip with her. </p>
<p>At length one shell cracked, and then another, and from each egg came a living creature that lifted its head and cried, “peep, peep.” “Quack, quack,” said the mother, and then they all were all quacks, and quacked as well as they could, and looked about them on every side at the large adsense slots. </p>
<p>Their mother allowed them to look as much as they liked, because green is good for the eyes. “How large the cyberspace is,” said the young white-hats, when they found how much more room they now had than while they were inside the egg-shell. “Do you imagine this is the whole cyberspace?” asked the mother; “Wait till you have seen the google; it stretches far beyond that to the Baidu, but I have never ventured to such a distance. Are you all out?” she continued, rising; “No, I declare, the largest egg lies there still. I wonder how long this is to last, I am quite tired of it;” and she seated herself again on the nest.</p>
<p>“Well, how are you getting on?” asked an old white-hat, who paid her a visit. “One egg is not hatched yet,” said the white-hat, “it will not break. But just look at all the others, are they not the prettiest little white-hatlings you ever saw? They are the image of Big Daddy, who is so unkind, he never comes to see.”</p>
<p>“Let me see the egg that will not break,” said the white-hat; “I have no doubt it is a spammer’s egg. I was persuaded to hatch some once, and after all my care and trouble with the young ones, they were afraid of the web. I quacked and clucked, but all to no purpose. I could not get them to venture in. Let me look at the egg. Yes, that is a spammer’s egg; take my advice, leave it where it is and teach the other children to kiss matt&#8217;s butt.”</p>
<p>“I think I will sit on it a little while longer,” said the white-hat; “as I have sat so long already, a few days will be nothing.” “Please yourself,” said the old white-hat, and she went away.</p>
<p>At last the large egg broke, and a young one crept forth crying, “PHP, PHP.” </p>
<p>It was very large and black. The white-hat stared at it and exclaimed, “It is very large and not at all like the others. I wonder if it really is a hacker. We shall soon find it out, however when we go to the web. It must go in, if I have to push it myself.”</p>
<p>On the next day the weather was delightful, and the sun shone brightly on the green burdock leaves, so the mother white-hat took her young brood down to the web, and jumped in with a splash. “Quack, quack,” cried she, and one after another the little white-hatlings jumped in. The web closed over their heads, but they came up again in an instant, and swam about quite prettily with their legs paddling under them as easily as possible, and the black-hatling was also in the web swimming with them.</p>
<p>“Oh,” said the mother, “that is not a spammer; how well he uses his legs, and how upright he holds himself! He is my own child, and he is not so very black after all if you look at him properly. Quack, quack! come with me now, I will take you into grand society, and introduce you to the Dmoz, but you must keep close to me or you may be trodden upon; and, above all, beware of the Aaron.”</p>
<p>When they reached the Dmoz, there was a great disturbance, two families were fighting for a toolbar, which, after all, was carried off by the Aaron. “See, children, that is the way of the world,” said the mother white-hat, whetting her beak, for she would have liked the toolbar herself. “Come, now, use your legs, and let me see how well you can behave. You must bow your heads prettily to that old white-hat yonder; she is the highest born of them all, and has Stanford blood, therefore, she is well off. Don’t you see she has a blue flag tied to her leg, which is something very grand, and a great honor for a white-hat; it shows that every one is anxious not to lose her, as she can be recognized both by man and beast. Come, now, don’t turn your toes, a well-bred white-hatling spreads his feet wide apart, just like his father and mother, in this way; now bend your neck, and say ‘<strong>quack</strong>.’”</p>
<p>The white-hatlings did as they were bid, but the other white-hat stared, and said, “Look, here comes another brood, as if there were not enough of us already! and what a weird looking object one of them is; we don’t want him here,” and then one flew out and bit him in the neck.</p>
<p>“Let him alone,” said the mother; “he is not doing any harm.”</p>
<p>“Yes, but he is so big and black,” said the spiteful white-hat “and therefore he must be turned out.”</p>
<p>“The others are very pretty children,” said the old white-hat, with the blue rag on her leg, “all but that one; I wish his mother could improve him a little.”</p>
<p>“That is impossible, your grace,” replied the mother; “he is not pretty; but he has a very good disposition, and swims as well or even better than the others. I think he will grow up pretty, and perhaps be smaller; he has remained too long in the egg, and therefore his figure is not properly formed;” and then she stroked his neck and smoothed the feathers, saying, “It is a drake, and therefore not of so much consequence. I think he will grow up strong, and able to take care of himself.”</p>
<p>“The other white-hatlings are graceful enough,” said the old white-hat. “Now make yourself at home, and if you can find a toolbar, you can bring it to me.”</p>
<p>And so they made themselves comfortable; but the poor black-hatling, who had crept out of his shell last of all, and looked so black, was bitten and pushed and made fun of, not only by the white-hats, but by all the googlebots. “He is too big,” they all said, and the DP admin, who had been born into the world with spurs, and fancied himself really an emperor, puffed himself out like a vessel in full sail, and flew at the black-hatling, and became quite red in the head with passion, so that the poor little thing did not know where to go, and was quite miserable because he was so black and laughed at by the whole dmoz. So it went on from day to day till it got worse and worse. The poor black-hatling was driven about by every one; even his brothers and sisters were unkind to him, and would say, “Ah, you black creature, I wish the Aaron would get you,” and his mother said she wished he had never been born. The white-hats pecked him, the chickens beat him, and the girl who fed the poultry kicked him with her feet. So at last he ran away, frightening the little birds in the hedge as he flew over the palings.</p>
<p>“They are afraid of me because I am black,” he said. So he closed his eyes, and flew still farther, until he came out on a large moor, inhabited by wild scripters. Here he remained the whole night, feeling very tired and sorrowful.</p>
<p>In the morning, when the wild scripters rose in the air, they stared at their new comrade. “What sort of a scripter are you?” they all said, coming round him.</p>
<p>He bowed to them, and was as polite as he could be, but he did not reply to their question. “You are exceedingly black,” said the wild scripter, “but that will not matter if you do not want to marry one of our family.”</p>
<p>Poor thing! he had no thoughts of marriage; all he wanted was permission to lie among the rushes, and drink some of the water on the moor. After he had been on the moor two days, there came two wild rappers, or rather youtubbies, for they had not been out of the egg long, and were very saucy. “Listen, friend,” said one of them to the black-hatling, “you are so black, that we like you very well. Will you go with us, and become a bird of passage? Not far from here is another moor, in which there are some pretty wild rapstresses, all unmarried. It is a chance for you to get a wife; you may be lucky, black as you are.”</p>
<p>“Pop, pop,” sounded in the air, and the two wild rappers fell dead among the rushes, and the web was tinged with blogreviews.</p>
<p>< snip (the part where all rappers get shot, google: 50cents if you're into that) ></p>
<p>It would be very sad, were I to relate all the misery and privations which the poor little black-hatling endured during the hard winter; but when it had passed, he found himself lying one morning in a dot org, amongst the PLR blogs. He felt the warm sun shining, and heard the lark singing, and saw that all around was beautiful spring. </p>
<p>Then the young bird felt that his wings were strong, as he flapped them against his sides, and rose high into the air. They bore him onwards, until he found himself in a large forum, before he well knew how it had happened. The threads were in full blossom, and the fragrant profiles bent their long iTraders down to the frontpage which wound round a smooth lounge. Everything looked beautiful, in the freshness of early spring. From a thicket close by came three beautiful webmasters, rustling their feathers, and swimming lightly over the smooth webr. The black-hatling remembered the lovely birds, and felt more strangely unhappy than ever.</p>
<p>“I will POST to those royal birds,” he exclaimed, “and they will blacklist me, because I am so black, and dare to approach them; but it does not matter: better be blacklisted by them than pecked by the white-hats, cursed by the copywriters, pushed about by Mad Butts, or starved with hunger in the winter.”</p>
<p>Then he logged onto the web, and surfed towards the beautiful webmasters. The moment they espied the stranger, they rushed to meet him with outstretched wings. “Blacklist me,” said the poor bird; and he bent his head down to the surface of the web, and awaited banishment.</p>
<p>But what did he see in the clear stream below? His own image; no longer a dark, gray bird, black and disagreeable to look at, but a graceful and beautiful webmaster. </p>
<p>To be born in a white-hat’s nest, in the google, is of no consequence to a bird, if it is hatched from a webmaster’s egg. </p>
<p>He now felt glad at having suffered sorrow and trouble, because it enabled him to enjoy so much better all the pleasure and happiness around him; for the great webmasters swam round the new-comer, and stroked his neck with their beaks, as a welcome.</p>
<p>Presently came some little children, and threw comments and backlinks into the web. “See,” cried the youngest, “there is a new one;” and the rest were delighted, and ran to their father and mother, dancing and clapping their hands, and shouting joyously, “There is another webmaster come; a new one has arrived.”</p>
<p>Then they threw more comments and backlinks into the web, and said, “The new one is the most beautiful of all; he is so young and xhmtl-compliant.” And the old webmasters bowed their heads before him.</p>
<p>Then he felt quite ashamed, and hid his head under his wing; for he did not know what to do, he was so happy, and yet not at all proud. He had been persecuted and despised for his blackness, and now he heard them say he was the most beautiful of all the birds. Even the elder-tree bent down its bows into the web before him, and the sun shone warm and bright. Then he rustled his feathers, curved his slender neck, and cried joyfully, from the depths of his heart, “I never dreamed of such happiness as this, while I was a black white-hatling.” </p>
<p>&#8212;&#8212;-<br />
<a href="http://hca.gilead.org.il/ugly_duc.html">original story</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.juust.org/index.php/the-black-hatling/2009/03/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RedHat Seo : scraper auto-blogging</title>
		<link>http://www.juust.org/index.php/redhat-seo-christmas-edition/2008/12/</link>
		<comments>http://www.juust.org/index.php/redhat-seo-christmas-edition/2008/12/#comments</comments>
		<pubDate>Fri, 26 Dec 2008 18:07:01 +0000</pubDate>
		<dc:creator>juust</dc:creator>
				<category><![CDATA[google]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[seo tips and tricks]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[wordpress]]></category>
		<category><![CDATA[xml-rpc]]></category>
		<category><![CDATA[scrape]]></category>

		<guid isPermaLink="false">http://www.juust.org/?p=270</guid>
		<description><![CDATA[Just give us your endpoint and we&#8217;ll take it from there, sparky! I was going to make one of these tools to scrape google and conjur a full blog out of nowhere, as Christmas special, RedHat Seo. The rough sketch &#8230; <a href="http://www.juust.org/index.php/redhat-seo-christmas-edition/2008/12/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<blockquote><p>Just give us your endpoint and we&#8217;ll take it from there, sparky!</p></blockquote>
<p>I was going to make one of these tools to scrape google and conjur a full blog out of nowhere, as Christmas special, RedHat Seo. The rough sketch has arrived , far from perfect, but it does produce a blog and don&#8217;t even look too shabby. I scraped a <a href="" rel="nofollow" target="_blank">small batch</a> of posts off of blogs, keeping the links intact and adding a tribute links. I hope they will pardon me for it. </p>
<h3>structure</h3>
<p>I use three main classes, </p>
<table>
<tbody>
<tr>
<td>BlogMaker    </td>
<td>     the application</td>
</tr>
<tr>
<td>Target         </td>
<td>     the blogs you aim for</td>
</tr>
<tr>
<td>WPContent   </td>
<td>     the scraped goodies</td>
</tr>
</tbody>
</table>
<p>&#8230;and two support classes</p>
<table>
<tbody>
<tr>
<td>SerpResult    </td>
<td>    scraped urls</td>
</tr>
<tr>
<td>Custom_RPC   </td>
<td>    a simple rpc-poster</td>
</tr>
</tbody>
</table>
<p>Target blogs have three texts, </p>
<table>
<tbody>
<tr>
<td>file</td>
<td>contents</td>
<td>maintenance</td>
</tr>
<tr>
<td>blog categories</td>
<td>category you post under</td>
<td>manual</td>
</tr>
<tr>
<td>blog tags</td>
<td> tags you list on the blog</td>
<td>manual</td>
</tr>
<tr>
<td>blog urls</td>
<td> urls already used for the blog</td>
<td>system</td>
</tr>
</tbody>
</table>
<h3>routine</h3>
<p>The BlogMaker class grabs a result list (up to 1000 urls per phrase) from Google, extracts the urls and stores them in SerpResult,  scrapes the urls and extracts the <strong>entry</strong> divs, stores div-entries in the WPContent class (that has some basic functions to sanitize the text), and uses the BlogTarget-definitions to post it up blogs with xml-rpc.</p>
<h3>usage</h3>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//make main instance</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$Blog</span> <span class="sy0">=</span> <span class="kw2">new</span> BlogMaker<span class="br0">&#40;</span><span class="st0">&quot;keyword&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//define a target blog, you can define multiple blogs and refer with code</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//then add rpc-url, password and user</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//and for every target blog three text-files </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$T</span><span class="sy0">=</span><span class="re1">$Blog</span><span class="sy0">-&gt;</span><span class="me1">AddTarget</span><span class="br0">&#40;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="st0">&#39;blogcode&#39;</span><span class="sy0">,</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="st0">&#39;http://my.blog.com/xmlrpc.php&#39;</span><span class="sy0">,</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="st0">&#39;password&#39;</span><span class="sy0">,</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="st0">&#39;user&#39;</span><span class="sy0">,</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="st0">&#39;keyword.categories.txt&#39;</span><span class="sy0">,</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="st0">&#39;keyword.tags.txt&#39;</span><span class="sy0">,</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="st0">&#39;keyword.urls.txt&#39;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//read the tags, cats and url text files stored on the server </span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//all retrieved urls are tested, if the target blog already has that</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//scraped url, it is discarded.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$T</span><span class="sy0">-&gt;</span><span class="me1">CSV_GetTags</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$T</span><span class="sy0">-&gt;</span><span class="me1">List_GetCats</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$T</span><span class="sy0">-&gt;</span><span class="me1">ReadURL</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//grab the google result list</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//use params (pages, keywords) to specify search</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$Blog</span><span class="sy0">-&gt;</span><span class="me1">GoogleResults</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$a</span><span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$Blog</span><span class="sy0">-&gt;</span><span class="me1">Results</span> <span class="kw1">as</span> <span class="re1">$BlogUrl</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> </div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re1">$a</span><span class="sy0">++;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">echo</span> <span class="re1">$BlogUrl</span><span class="sy0">-&gt;</span><span class="me1">url</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//see if the url isnt used yet</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">if</span><span class="br0">&#40;</span><span class="re1">$T</span><span class="sy0">-&gt;</span><span class="me1">checkURL</span><span class="br0">&#40;</span><span class="kw3">trim</span><span class="br0">&#40;</span><span class="re1">$BlogUrl</span><span class="sy0">-&gt;</span><span class="me1">url</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">!=</span><span class="kw2">true</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw3">echo</span> <span class="st0">&#39;&#8230;checking &#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw3">flush</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//if not used, get the source</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="re1">$BlogUrl</span><span class="sy0">-&gt;</span><span class="me1">scrape</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//check for divs marked &quot;entry&quot;, if they arent there, check &quot;post&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//some blogs use other indications for the content</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//but entry and post cover 40%</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="re1">$entries</span> <span class="sy0">=</span> <span class="re1">$BlogUrl</span><span class="sy0">-&gt;</span><span class="me1">get_entries</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">count</span><span class="br0">&#40;</span><span class="re1">$entries</span><span class="br0">&#41;</span><span class="sy0">&amp;</span>lt<span class="sy0">;</span><span class="nu0">1</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">echo</span> <span class="st0">&#39;no entries&#8230;&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">flush</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$entries</span> <span class="sy0">=</span> <span class="re1">$BlogUrl</span><span class="sy0">-&gt;</span><span class="me1">get_posts</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw1">if</span><span class="br0">&#40;</span><span class="kw3">count</span><span class="br0">&#40;</span><span class="re1">$entries</span><span class="br0">&#41;</span><span class="sy0">&amp;</span>lt<span class="sy0">;</span><span class="nu0">1</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="kw3">echo</span> <span class="st0">&#39;no posts either&#8230;&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//if no entry-post div, mark url as done</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="re1">$T</span><span class="sy0">-&gt;</span><span class="me1">RegisterURL</span><span class="br0">&#40;</span><span class="re1">$BlogUrl</span><span class="sy0">-&gt;</span><span class="me1">url</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="re1">$ct</span><span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$BlogUrl</span><span class="sy0">-&gt;</span><span class="me1">WpContentPieces</span> <span class="kw1">as</span> <span class="re1">$WpContent</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//in the get_entries/get_post function the fragments are stored</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//as wpcontent</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re1">$ct</span><span class="sy0">++;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="re1">$WpContent</span><span class="sy0">-&gt;</span><span class="me1">judge</span><span class="br0">&#40;</span><span class="nu0">2000</span><span class="sy0">,</span> <span class="nu0">200</span><span class="sy0">,</span> <span class="nu0">5</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="re1">$WpContent</span><span class="sy0">-&gt;</span><span class="me1">tribute</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span> &nbsp;<span class="co1">//add tribute link</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="re1">$T</span><span class="sy0">-&gt;</span><span class="me1">settags</span><span class="br0">&#40;</span><span class="re1">$WpContent</span><span class="sy0">-&gt;</span><span class="me1">divcontent</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//add tags</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="re1">$T</span><span class="sy0">-&gt;</span><span class="me1">postCustomRPC</span><span class="br0">&#40;</span><span class="re1">$WpContent</span><span class="sy0">-&gt;</span><span class="me1">title</span><span class="sy0">,</span> <span class="re1">$WpContent</span><span class="sy0">-&gt;</span><span class="me1">divcontent</span><span class="sy0">,</span> <span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span> <span class="co1">//1=publish, 0=draft</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="re1">$T</span><span class="sy0">-&gt;</span><span class="me1">RegisterURL</span><span class="br0">&#40;</span><span class="re1">$WpContent</span><span class="sy0">-&gt;</span><span class="me1">url</span><span class="br0">&#41;</span><span class="sy0">;</span> &nbsp;<span class="co1">//register use of url</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">usleep</span><span class="br0">&#40;</span><span class="nu0">20000000</span><span class="br0">&#41;</span><span class="sy0">;</span> &nbsp;<span class="co1">//20 seconds break, for sitemapping</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<h3>notes</h3>
<ul>
<li>xml-rpc needs to be activated explicitly on the wordpress dashboard under settings/writing.</li>
<li>categories must be present in the blog</li>
<li>url file must be writeable by the server (777)</li>
</ul>
<p>It seems wordpress builds the sitemap as background process, the standard google xml sitemap plugin wil attempt to build in the cache (takes anywhere between 2 and 10 seconds), and apart from building a sitemap the posts also get pinged around. Giving the install 10 to 20 seconds between posts allows for all the hooked in functions to be completed.</p>
<h3>period</h3>
<p>That&#8217;s about all,<br />
consider it gpl, I added some comments in the source but I will not develop this any further. A mysql backed blogfarm tool (euphemistically called &#8216;publishing tool&#8217;) is more interesting, besides, I am off to the wharves to do some painting.</p>
<p>if you use it, send some feedback,<br />
merry christmas dogheads</p>
]]></content:encoded>
			<wfw:commentRss>http://www.juust.org/index.php/redhat-seo-christmas-edition/2008/12/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>google trends III</title>
		<link>http://www.juust.org/index.php/google-trends-iii/2008/12/</link>
		<comments>http://www.juust.org/index.php/google-trends-iii/2008/12/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 23:53:14 +0000</pubDate>
		<dc:creator>juust</dc:creator>
				<category><![CDATA[google]]></category>
		<category><![CDATA[scrape]]></category>
		<category><![CDATA[trends]]></category>

		<guid isPermaLink="false">http://www.juust.org/?p=271</guid>
		<description><![CDATA[How to get the urls and snippets from the Google Trends details page. The news articles on the details page are listed with an &#8216;Ajax&#8217; call, they are not sent to the browser in the html source. No easy way &#8230; <a href="http://www.juust.org/index.php/google-trends-iii/2008/12/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>How to get the urls and snippets from the Google Trends details page. The news articles on the details page are listed with an &#8216;Ajax&#8217; call, they are not sent to the browser in the html source. No easy way to scrape that. </p>
<p>The blog articles are pretty straight forward : first the ugly fast way :</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="re1">$mytitle</span><span class="sy0">=</span><span class="st0">&#39;manuel benitez&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$mydate</span><span class="sy0">=</span><span class="st0">&#39;&#39;</span><span class="sy0">;</span> <span class="co1">//2008-12-24</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$html</span><span class="sy0">=</span><span class="kw3">file_get_contents</span><span class="br0">&#40;</span><span class="st0">&#39;http://www.google.com/trends/hottrends?q=&#39;</span><span class="sy0">.</span><span class="kw3">urlencode</span><span class="br0">&#40;</span><span class="re1">$mytitle</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&#39;&amp;date=&amp;sa=X&#39;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$start</span> <span class="sy0">=</span> <span class="kw3">strpos</span><span class="br0">&#40;</span><span class="re1">$html</span><span class="sy0">,</span> <span class="st0">&#39;&lt;div class=&quot;gsc-resultsbox-visible&quot;&gt;&#39;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$end</span> <span class="sy0">=</span> <span class="kw3">strpos</span><span class="br0">&#40;</span><span class="re1">$html</span><span class="sy0">,</span> <span class="st0">&#39;&lt;div class=&quot;gsc-trailing-more-results&quot;&gt;&#39;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$content</span> <span class="sy0">=</span> <span class="kw3">substr</span><span class="br0">&#40;</span><span class="re1">$html</span><span class="sy0">,</span> <span class="re1">$start</span><span class="sy0">,</span> <span class="re1">$end</span><span class="sy0">-</span><span class="re1">$start</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="re1">$content</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>div<span class="sy0">&gt;&lt;/</span>div<span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p>That returns the blog snippets, ugly. The other way : regular pattern matching : you can grab the divs that each content item has, marked with</p>
<ul>
<li>div class=&#8221;gs-title&#8221;</li>
<li>div class=&#8221;gs-relativePublishedDate&#8221;</li>
<li>div class=&#8221;gs-snippet&#8221;</li>
<li>div class=&#8221;gs-visibleUrl&#8221;</li>
</ul>
<p>from the html-source and organize them as &#8220;Content&#8221; array, after which you can list the content items with your own markup or store them in a database.</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="co1">//I assume $mytitle is taken from the $_GET array.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//array &#39;Content&#39; with it&#39;s members </span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">Class</span> Content <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">var</span> <span class="re1">$id</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">var</span> <span class="re1">$title</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">var</span> <span class="re1">$pubdate</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">var</span> <span class="re1">$snippet</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">var</span> <span class="re1">$url</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw2">public</span> <span class="kw2">function</span> __construct<span class="br0">&#40;</span><span class="re1">$id</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="re1">$this</span><span class="sy0">-&gt;</span><span class="me1">id</span><span class="sy0">=</span><span class="re1">$id</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//grab the source from the google page</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$html</span><span class="sy0">=</span><span class="kw3">file_get_contents</span><span class="br0">&#40;</span><span class="st0">&#39;http://www.google.com/trends/hottrends?q=&#39;</span><span class="sy0">.</span><span class="kw3">urlencode</span><span class="br0">&#40;</span><span class="re1">$mytitle</span><span class="br0">&#41;</span><span class="sy0">.</span><span class="st0">&#39;&amp;date=&amp;sa=X&#39;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//cut out the part I want</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$start</span> <span class="sy0">=</span> <span class="kw3">strpos</span><span class="br0">&#40;</span><span class="re1">$html</span><span class="sy0">,</span> <span class="st0">&#39;&lt;div class=&quot;gsc-resultsbox-visible&quot;&gt;&#39;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$end</span> <span class="sy0">=</span> <span class="kw3">strpos</span><span class="br0">&#40;</span><span class="re1">$html</span><span class="sy0">,</span> <span class="st0">&#39;&lt;div class=&quot;gsc-trailing-more-results&quot;&gt;&#39;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$content</span> <span class="sy0">=</span> <span class="kw3">substr</span><span class="br0">&#40;</span><span class="re1">$html</span><span class="sy0">,</span> <span class="re1">$start</span><span class="sy0">,</span> <span class="re1">$end</span><span class="sy0">-</span><span class="re1">$start</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//grab the divs that contain title, publish date, snippet and url with regular pattern match</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">preg_match_all</span><span class="br0">&#40;</span><span class="st0">&#39;!&lt;div class=<span class="es0">\&#8221;</span>gs-title<span class="es0">\&#8221;</span>&gt;.*?&lt; <span class="es0">\/</span>div&gt;!si&#39;</span><span class="sy0">,</span> <span class="re1">$html</span><span class="sy0">,</span> <span class="re1">$titles</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">preg_match_all</span><span class="br0">&#40;</span><span class="st0">&#39;!&lt;div class=<span class="es0">\&#8221;</span>gs-relativePublishedDate<span class="es0">\&#8221;</span>&gt;.*?&lt; <span class="es0">\/</span>div&gt;!si&#39;</span><span class="sy0">,</span> <span class="re1">$html</span><span class="sy0">,</span> <span class="re1">$pubDates</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">preg_match_all</span><span class="br0">&#40;</span><span class="st0">&#39;!&lt;div class=<span class="es0">\&#8221;</span>gs-snippet<span class="es0">\&#8221;</span>&gt;.*?&lt; <span class="es0">\/</span>div&gt;!si&#39;</span><span class="sy0">,</span> <span class="re1">$html</span><span class="sy0">,</span> <span class="re1">$snippets</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">preg_match_all</span><span class="br0">&#40;</span><span class="st0">&#39;!&lt;div class=<span class="es0">\&#8221;</span>gs-visibleUrl<span class="es0">\&#8221;</span>&gt;.*?&lt; <span class="es0">\/</span>div&gt;!si&#39;</span><span class="sy0">,</span> <span class="re1">$html</span><span class="sy0">,</span> <span class="re1">$urls</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$Contents</span> <span class="sy0">=</span> <span class="kw3">array</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//organize them under Content;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$count</span><span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$titles</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> <span class="kw1">as</span> <span class="re1">$title</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//make a new instance of Content;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$Contents</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy0">=</span> <span class="kw2">new</span> Content<span class="br0">&#40;</span><span class="re1">$count</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//add title</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$Contents</span><span class="br0">&#91;</span><span class="re1">$count</span><span class="br0">&#93;</span><span class="sy0">-&gt;</span><span class="me1">title</span><span class="sy0">=</span><span class="re1">$title</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$count</span><span class="sy0">++;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$count</span><span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$pubDates</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> <span class="kw1">as</span> <span class="re1">$pubDate</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//add publishing date (contains some linebreak, remove it with strip_tags)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$Contents</span><span class="br0">&#91;</span><span class="re1">$count</span><span class="br0">&#93;</span><span class="sy0">-&gt;</span><span class="me1">pubdate</span><span class="sy0">=</span><span class="kw3">strip_tags</span><span class="br0">&#40;</span><span class="re1">$pubDate</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$count</span><span class="sy0">++;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$count</span><span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$snippets</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> <span class="kw1">as</span> <span class="re1">$snippet</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//add snippet</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$Contents</span><span class="br0">&#91;</span><span class="re1">$count</span><span class="br0">&#93;</span><span class="sy0">-&gt;</span><span class="me1">snippet</span><span class="sy0">=</span><span class="re1">$snippet</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$count</span><span class="sy0">++;</span> </div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re1">$count</span><span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">foreach</span><span class="br0">&#40;</span><span class="re1">$urls</span><span class="br0">&#91;</span><span class="nu0">0</span><span class="br0">&#93;</span> <span class="kw1">as</span> <span class="re1">$url</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//add display url</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$Contents</span><span class="br0">&#91;</span><span class="re1">$count</span><span class="br0">&#93;</span><span class="sy0">-&gt;</span><span class="me1">url</span><span class="sy0">=</span><span class="re1">$url</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$count</span><span class="sy0">++;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//leave $count as is, the number of content-items with a 0-base array</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//add rel=nofollow to links to prevent pagerank assignment to blogs</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span><span class="br0">&#40;</span><span class="re1">$ct</span><span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span><span class="re1">$ct</span><span class="sy0">&lt;</span> <span class="re1">$count</span><span class="sy0">;</span><span class="re1">$ct</span><span class="sy0">++</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$Contents</span><span class="br0">&#91;</span><span class="re1">$ct</span><span class="br0">&#93;</span><span class="sy0">-&gt;</span><span class="me1">url</span> <span class="sy0">=</span> <span class="kw3">preg_replace</span><span class="br0">&#40;</span><span class="st0">&#39;/ target/&#39;</span><span class="sy0">,</span> <span class="st0">&#39; rel=&quot;nofollow&quot; target&#39;</span><span class="sy0">,</span> <span class="re1">$Contents</span><span class="br0">&#91;</span><span class="re1">$ct</span><span class="br0">&#93;</span><span class="sy0">-&gt;</span><span class="me1">url</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="re1">$Contents</span><span class="br0">&#91;</span><span class="re1">$ct</span><span class="br0">&#93;</span><span class="sy0">-&gt;</span><span class="me1">title</span> <span class="sy0">=</span> <span class="kw3">preg_replace</span><span class="br0">&#40;</span><span class="st0">&#39;/ target/&#39;</span><span class="sy0">,</span> <span class="st0">&#39; rel=&quot;nofollow&quot; target&#39;</span><span class="sy0">,</span> <span class="re1">$Contents</span><span class="br0">&#91;</span><span class="re1">$ct</span><span class="br0">&#93;</span><span class="sy0">-&gt;</span><span class="me1">title</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">//its complete, list all content-items with some markup</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span><span class="br0">&#40;</span><span class="re1">$ct</span><span class="sy0">=</span><span class="nu0">0</span><span class="sy0">;</span><span class="re1">$ct</span><span class="sy0">&lt;</span> <span class="re1">$count</span><span class="sy0">;</span><span class="re1">$ct</span><span class="sy0">++</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">echo</span> <span class="st0">&#39;&lt;h3&gt;&#39;</span><span class="sy0">.</span><span class="re1">$Contents</span><span class="br0">&#91;</span><span class="re1">$ct</span><span class="br0">&#93;</span><span class="sy0">-&gt;</span><span class="me1">title</span><span class="sy0">.</span><span class="st0">&#39;&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">echo</span> <span class="st0">&#39;&lt;p&gt;&lt;strong&gt;&#39;</span><span class="sy0">.</span><span class="re1">$Contents</span><span class="br0">&#91;</span><span class="re1">$ct</span><span class="br0">&#93;</span><span class="sy0">-&gt;</span><span class="me1">pubdate</span><span class="sy0">.</span><span class="st0">&#39;&lt;/strong&gt;:&lt;em&gt;&#39;</span><span class="sy0">.</span><span class="re1">$Contents</span><span class="br0">&#91;</span><span class="re1">$ct</span><span class="br0">&#93;</span><span class="sy0">-&gt;</span><span class="me1">snippet</span><span class="sy0">.</span><span class="st0">&#39;&lt;/em&gt;&lt;/p&gt;&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">echo</span> <span class="re1">$Contents</span><span class="br0">&#91;</span><span class="re1">$ct</span><span class="br0">&#93;</span><span class="sy0">-&gt;</span><span class="me1">url</span><span class="sy0">.</span><span class="st0">&#39;&lt;br /&gt;&#39;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>div<span class="sy0">&gt;&lt;/</span>div<span class="sy0">&gt;&lt;/</span>div<span class="sy0">&gt;&lt;/</span>div<span class="sy0">&gt;&lt;/</span>div<span class="sy0">&gt;&lt;/</span>div<span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p>It ain&#8217;t perfect, but it works. the highlighter I use gets a bit confused about the preg_match_all statements containing unclosed div&#8217;s, so copying the code of the blog may not work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.juust.org/index.php/google-trends-iii/2008/12/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

