<?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; curl</title>
	<atom:link href="http://www.rainmoe.com/tag/curl/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rainmoe.com</link>
	<description>One code, one world ...</description>
	<lastBuildDate>Thu, 29 Dec 2011 14:04:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>圣诞小礼物：动漫美图站抓取函数，Free域名扫描函数</title>
		<link>http://www.rainmoe.com/2010/12/27/xmas-gifts/</link>
		<comments>http://www.rainmoe.com/2010/12/27/xmas-gifts/#comments</comments>
		<pubDate>Sun, 26 Dec 2010 19:04:26 +0000</pubDate>
		<dc:creator>小邪</dc:creator>
				<category><![CDATA[作品 [Work]]]></category>
		<category><![CDATA[comic]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[dotfree]]></category>
		<category><![CDATA[picture]]></category>
		<category><![CDATA[scanner]]></category>

		<guid isPermaLink="false">http://www.evlos.org/?p=2135</guid>
		<description><![CDATA[　　嘿嘿，小邪这次试着修改了文风 o(*￣▽￣*)ゞ，不然的话写一篇文章实在是太累鸟。之前小邪一直是写几行就按一次保存草稿，再按一次预览。只是为了让整个文章看起来像是有种命令行 (Shell) 的效果 (每个">"占一行)。果断纠正过来，不能让写博变成折磨 - -。



一. 礼物一 - 动漫美图站抓取函数：

<span class="readmore"><a href="http://www.rainmoe.com/2010/12/27/xmas-gifts/" title="圣诞小礼物：动漫美图站抓取函数，Free域名扫描函数">阅读全文——共306字</a></span>]]></description>
			<content:encoded><![CDATA[<p>　　嘿嘿，小邪这次试着修改了文风 o(*￣▽￣*)ゞ，不然的话写一篇文章实在是太累鸟。之前小邪一直是写几行就按一次保存草稿，再按一次预览。只是为了让整个文章看起来像是有种命令行 (Shell) 的效果 (每个">"占一行)。果断纠正过来，不能让写博变成折磨 - -。</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/2010/12/k91441.jpg" alt="" title="" width="600" height="343" class="alignnone size-full wp-image-2163" /></p>
<p><span id="more-2135"></span><strong>一. 礼物一 - 动漫美图站抓取函数：</strong></p>
<p>　　话说 <a target='_blank' rel='nofollow' href='http://konachan.com/post'>Konachan.com</a> 是一个灰常强力的动漫美图发布站点，上面的图片，-________-，貌似只能用很给力和应该被打上马赛克两个短语来形容鸟 ╮(╯▽╰)╭。</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/2010/12/Cap0003716.png" alt="" title="" width="600" height="350" class="alignnone size-full wp-image-2161" /></p>
<p>　　不知道国内有没有被墙，[= =]，嘿嘿，不行的话可以放在你们美国主机上面来运行。额，这里木有给出整个程序，因为从站长的角度来说，“抓取”实在是太残忍了 ~(>_<)~，所以咱也不能太那个了，只是分享一下可以根据ID来抓取单个图片下载地址的程序（其实，批量下载加个循环就可以了，嘿嘿嘿嘿嘿嘿）。</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/2010/12/k91483.jpg" alt="" title="" width="600" height="475" class="alignnone size-full wp-image-2162" /></p>
<p>　　此站点做了一点点类似防盗链的东东，也就是只能直接在地址栏里面输入图片地址。否则的话，唔，假设我们在某个网页上面提供了指向图片源文件的链接，你点击进去的时候显示的不是图片，而是图片浏览页面。嘿嘿，这种情况其实没啥影响的，如果你直接通过迅雷下载（唔，对你的电脑做好心理准备吧，不知道一次导入90000条下载地址会不会爆掉 ╮(╯_╰)╭）的话，完全可以正常下载，要使用CURL函数下载也行（话说90000张图片用PHP来下载也太悲催了 - -||）。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
/**
* Konachan.com image downloader v0.0.1 Alpha
* @param string $id
* @return image url or error report
* Made by Evlos
**/
function ev_konachan_imageurl_catcher($id) {
  function ev_html_catcher($url,$cookie='') {
    $curl = curl_init($url);
    $useragent=&quot;Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1)&quot;;
    $useragent.=&quot; Gecko/20061204 Firefox/2.0.0.1&quot;;
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt ($curl, CURLOPT_USERAGENT, $useragent);
    if ($cookie&lt;&gt;'') curl_setopt ($curl, CURLOPT_COOKIE, $cookie);
    $data = curl_exec($curl);
    curl_close($curl);
    return $data;
  }
  $html = ev_html_catcher('http://konachan.com/post/show/'.$id.'/');
  if (preg_match('/&lt;a href=&quot;([^&quot;]+)&quot; class=&quot;[^&quot;]+&quot; id=&quot;png&quot;&gt;/i',$html,$tmp)) {
    return $tmp[1];
  } else if (preg_match('/&lt;a href=&quot;([^&quot;]+)&quot; class=&quot;[^&quot;]+&quot; id=&quot;highres&quot;&gt;/i',
    $html,$tmp)) {
    return $tmp[1];
  }
  else if (preg_match('/&lt;p&gt;This post does not exist.&lt;\/p&gt;/i',$html,$tmp)) {
    return 'This post does not exist.';
  } else if (preg_match('/This post was deleted./i',$html,$tmp)) {
    return 'This post was deleted.';
  } else {
    return 'Error [&gt;.&lt;].';
  }
}
</pre>
<p>　　那个，然后是关于源代码的解说。首先是灰常强力的 ev_html_catcher 目标网页源代码抓取函数，o(*￣▽￣*)ゞ。这个函数会返回目标URL的源代码，并且是字符串形式滴。接着咱们用正则式给他把图片抓下来即可，首先抓PNG格式（图片效果无损失）的判断，如果木有PNG格式，就抓取相对差一些的JPG图片地址。</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/2010/12/k91367.jpg" alt="" title="" width="600" height="424" class="alignnone size-full wp-image-2165" /></p>
<p>　　嘿嘿，各种圣诞福利图片。接着说，就是还有 "This post does not exist" 和 "This post was deleted" 两种情况，碰到这两种情况，小邪的函数就直接返回整个字符串鸟，这样子容易调试程序一点喔。唔，建议写批量抓取代码的时候对返回 "Error [>.<]" 的情况再重试几次，防止漏抓嘛。接着给抓取程序加上习惯性的 "set_time_limit(0);" 来去除PHP的默认程序运行超过30s还木有结束就提示错误超时的设定。</p>
<p><strong>二. 礼物二 - DotFree域名扫描函数：</strong></p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
/**
* Dot free domain scanner v0.0.1 Alpha
* @param string $domain_name
* @return true or false
* Made by Evlos
**/
function ev_dotfree_scaner($domain_name) {
  $o = ''; $post_data = array();
  $post_data['name'] = $domain_name;
  $url = 'http://www.dotfree.com/register/checkname.php';
  foreach ($post_data as $k=&gt;$v) $o.= &quot;$k=&quot;.urlencode($v).&quot;&amp;&quot;;
  $post_data = substr($o,0,-1);
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_URL,$url);
  curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
  curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  $arr = json_decode(curl_exec($ch));
  if ($arr-&gt;result==0) return true; else return false;
}
</pre>
<p>　　前段时间 .free 域名很火，不过小邪也觉得就是玩玩，毕竟 .free 做后缀怎么看怎么杯具 - -，所以大家有兴趣可以自己扫个，没兴趣直接跳过就好鸟。</p>
<p><strong>三. 附带礼物三 - 批量处理程序的制作技巧：</strong></p>
<p>　　首先下面这段程序，第一段 Javascript 代码是表示 3 秒以后自动刷新本页面，放心咯，带参数的页面也木有问题的。然后第二段则是 3 秒以后自动转向到目标地址。这样子 o(*￣▽￣*)ゞ，就可以比如一次处理 100 条，然后转向，继续处理下一百条。那个，别忘记处理到最后一个 ID 的时候加个判断自动停止啊，不然你的电脑也太杯具了 ╮(╯▽╰)╭。</p>
<pre class="brush: jscript; auto-links: false; html-script: false; title: ; notranslate">
&lt;script language=&quot;javascript&quot;&gt;
  setInterval(&quot;window.location.reload()&quot;,3000)
&lt;/script&gt;
&lt;script language=&quot;javascript&quot;&gt;
  setInterval(&quot;window.location.href='./?p=&lt;?php echo ($page+1); ?&gt;'&quot;,3000)
&lt;/script&gt;
</pre>
<p><img src="http://www.rainmoe.com/wp-content/uploads/2010/12/k91261.jpg" alt="" title="" width="600" height="375" class="alignnone size-full wp-image-2166" /></p>
<p>　　关于页码处理的技巧，木有带页码参数就直接认为是第一页，带了参数的就直接把页码送到处理的函数里面去即可，W(￣_￣)W。然后记得在那个函数里面加个判断，如果本页最后的ID超过了总ID数量，就把最后的ID缓存总ID数量。下面一行则是防止本页最前面的ID不要超过最后的ID，囧，不知道会不会这样，反正加个保险啦。o(*￣▽￣*)ゞ。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
if (isset($_GET['p'])) ev_content_echo(100,$_GET['p'],91503);
	else ev_content_echo(100,1,91503);

$end = $perpage*$page; $begin = $perpage*($page-1)+1;
if ($end&lt;=$count) $end = $perpage*$page; else $end = $count;
if ($begin&lt;=$end) $begin = $perpage*($page-1)+1; else $begin=$end-10;
</pre>
<p><strong>四. 邪恶代码学习计划：</strong></p>
<p>　　嘿嘿嘿嘿嘿嘿 o(*￣▽￣*)ゞ，以后你们不想看代码，小邪就用动漫美图来勾引你们，哇卡卡卡卡。</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/2010/12/k91405.jpg" alt="" title="" width="600" height="450" class="alignnone size-full wp-image-2164" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rainmoe.com/2010/12/27/xmas-gifts/feed/</wfw:commentRss>
		<slash:comments>238</slash:comments>
		</item>
		<item>
		<title>突破防盗链抓取漫画文件方法简述</title>
		<link>http://www.rainmoe.com/2010/05/04/download-comic/</link>
		<comments>http://www.rainmoe.com/2010/05/04/download-comic/#comments</comments>
		<pubDate>Mon, 03 May 2010 17:43:01 +0000</pubDate>
		<dc:creator>小邪</dc:creator>
				<category><![CDATA[作品 [Work]]]></category>
		<category><![CDATA[comic]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[download]]></category>

		<guid isPermaLink="false">http://www.evlos.org/?p=1955</guid>
		<description><![CDATA[> 嘿嘿，小邪最近想批量下载某个网站的漫画，因为那里的广告实在是太多了，- -，漫画都遮住了。

> 广告就算是被 Chrome 屏蔽了，居然还带声音，要是多开几个页面就那个诡异啊，0.0，狂汗。



<span class="readmore"><a href="http://www.rainmoe.com/2010/05/04/download-comic/" title="突破防盗链抓取漫画文件方法简述">阅读全文——共1678字</a></span>]]></description>
			<content:encoded><![CDATA[<p>> 嘿嘿，小邪最近想批量下载某个网站的漫画，因为那里的广告实在是太多了，- -，漫画都遮住了。<br />
> 广告就算是被 Chrome 屏蔽了，居然还带声音，要是多开几个页面就那个诡异啊，0.0，狂汗。</p>
<p><img src='http://www.rainmoe.com/wp-content/uploads/old/Cap0000383.png' /></p>
<p><span id="more-1955"></span><strong>一. 如何突破防盗链：</strong></p>
<p>> 一般的防盗链都是检测头部的 Referer 属性，也就是我们正在访问的调用图片的那个页面的地址。<br />
> 通过这个地址来检测你是否是从此页面（即允许调用图片的网站）来访问图片的，然后进行判断。<br />
> 看看是输出防盗链防御图片，O(∩_∩)O，还是输出你要浏览的漫画文件内容，嘎嘎，╮(╯▽╰)╭。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
$url = 'http://xx.xxxxxcomic.com/xxx/xxxx/xxxxx/act_001/001Xsss.JPG';
//这个变量是要下载的图片地址
$referer = 'http://www.xxxxxcomic.com/manhua/xxxx/xxxxxx/?a=1';
//这个变量是我们需要伪造的头部 Referer 属性内容，也就是显示此图片的页面地址
function downloader($url,$referer,$name) {
	$curl = curl_init($url);
	$useragent=&quot;Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.2.4) Gecko/20100413 Firefox/3.6.4&quot;;
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt ($curl, CURLOPT_USERAGENT, $useragent);
	curl_setopt($curl, CURLOPT_REFERER, $referer);
	$data = curl_exec($curl);
	curl_close($curl);
	//以上构造一个 Curl 函数来下载图片的内容
	$handle = fopen($name,'w+');
	fwrite($handle,$data);
	fclose($handle);
	//再用 fopen fwrite fclose 来将内容保存为文件
}
downloader($url,$referer,'1.jpg');
//'1.jpg' 则是图片的文件名，这样调用就可以成功下载了喔
</pre>
<p>> 咱点到即止哈，这种事情不能讲得太细的，毕竟影响到了这些站点的生意了，这样很不好呢。<br />
> 所以我们以研究 PHP 代码技术的角度简单注释一下，希望对大家有用喔，O(∩_∩)O 嘻嘻。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
var ServerList= new Array(12);
ServerList[0]=&quot;http://21.xxxxxcomic.com/xxx1/&quot;;
ServerList[1]=&quot;http://21.xxxxxcomic.com/xxx2/&quot;;
ServerList[2]=&quot;http://32.xxxxxcomic.com/xxx3/&quot;;
</pre>
<p>> 如果图片是延迟载入的，即页面载入完成才载入图片，那在某 JS 文件可能找到上面内容喔。<br />
> 这是基本地址，随机读取的，一般是漫画文件 URL 的前半部分，嘎嘎，可能随时更换的。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
&lt;script language=&quot;javascript&quot;&gt;
var ComicListID=41870;
var ComicID=5165;
var PicListUrl = &quot;/xxx001.JPG|/xxx002.JPG&quot;;
//在漫画浏览页面代码中还可能找到这样的地址，表示此章节漫画文件名称，接在基本地址后边即可
&lt;/script&gt;
</pre>
<p>> 嘻嘻，那么祝大家玩得开心哈，小邪闪人咯。嘎嘎嘎嘎。╮(╯-╰)╭╮(╯o╰)╭╮(╯O╰)╭╮(╯▽╰)╭。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rainmoe.com/2010/05/04/download-comic/feed/</wfw:commentRss>
		<slash:comments>98</slash:comments>
		</item>
		<item>
		<title>Photobucket抓取图片下载程序</title>
		<link>http://www.rainmoe.com/2010/01/14/photobucket-downloader/</link>
		<comments>http://www.rainmoe.com/2010/01/14/photobucket-downloader/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 15:38:52 +0000</pubDate>
		<dc:creator>小邪</dc:creator>
				<category><![CDATA[作品 [Work]]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[photobucket]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.evlos.org/?p=1898</guid>
		<description><![CDATA[> 最近小邪抓取抓上瘾鸟，感觉 Curl 与 正则式 的组合很爽，╮(╯▽╰)╭，拦都拦不住自己呐。

> 所以今天小邪要送大家一个 Photobucket 抓取程序，可以很方便地抓取整个相册喔。



<span class="readmore"><a href="http://www.rainmoe.com/2010/01/14/photobucket-downloader/" title="Photobucket抓取图片下载程序">阅读全文——共734字</a></span>]]></description>
			<content:encoded><![CDATA[<p>> 最近小邪抓取抓上瘾鸟，感觉 Curl 与 正则式 的组合很爽，╮(╯▽╰)╭，拦都拦不住自己呐。<br />
> 所以今天小邪要送大家一个 Photobucket 抓取程序，可以很方便地抓取整个相册喔。</p>
<p><img src='http://www.rainmoe.com/wp-content/uploads/old/Capture1141.jpg' /></p>
<p>> 程序的运行过程是这个样子的，先读取相册页面，然后用正则式找到文件名与地址。<br />
> 最后用 set_time_limit(0) 设置防止超时，并用 File_get_contents 函数把图片下载下来。</p>
<p><span id="more-1898"></span><strong>一. PBK Downloader 程序简介：</strong></p>
<p>> 在变量 album_url 里填上相册地址，然后在变量 album_pagen 里填上页数即可。<br />
> 程序会自动生成一个 Img 文件夹，并将图片下载到里面，就完成咯，O(∩_∩)O 嘻嘻！</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
$album_url = 'http://photobucket.com/images/avatar%20movie/'; //相册
$album_pagen = 1; //页数
</pre>
<p><strong>二. 抓取实例：</strong></p>
<p>> 相册地址 - <a target='_blank' rel='nofollow' href='http://photobucket.com/images/avatar%20movie/'>http://photobucket.com/images/avatar%20movie/</a></p>
<p><img src='http://www.rainmoe.com/wp-content/uploads/old/Capture1140.jpg' /></p>
<p>> 呵呵，小邪在页数那里只填了1页，然后就抓取下来咯。小邪文件名前面加了序号来着。<br />
> 因为有些图片名字相同，但是内容却是不同的，所以这样子防止出现漏掉文件。</p>
<p><img src='http://www.rainmoe.com/wp-content/uploads/old/Capture1143.jpg' /></p>
<p><strong>三. 源代码：</strong></p>
<p>> 把下面两个变量填一下就好，小邪已经把超时设置为无限，但是如果出现意外状况。<br />
> 直接刷新接着来就好，程序如果发现已经下载了就不会下第二遍咯，O(∩_∩)O。</p>
<p>> <a target='_blank' rel='nofollow' href='http://code.google.com/p/evlosbox/downloads/detail?name=pbk_getpic.txt&#038;can=2&#038;q='>http://code.google.com/p/evlosbox/downloads/detail?name=pbk_getpic.txt</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rainmoe.com/2010/01/14/photobucket-downloader/feed/</wfw:commentRss>
		<slash:comments>112</slash:comments>
		</item>
		<item>
		<title>如何抓取Flickr相片集中的图片URL</title>
		<link>http://www.rainmoe.com/2010/01/10/get-the-files-and-urls-from-flickr/</link>
		<comments>http://www.rainmoe.com/2010/01/10/get-the-files-and-urls-from-flickr/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 18:13:45 +0000</pubDate>
		<dc:creator>小邪</dc:creator>
				<category><![CDATA[作品 [Work]]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.evlos.org/?p=1893</guid>
		<description><![CDATA[> 最近小邪准备把博客的图片地址都换成 Flickr 上面的图片地址，所以需要用抓取来节省时间。

> 恩恩，纯粹是节省时间，抓取对很多盆友都是不好的事情，小邪的站也被抓过，很杯具。



<span class="readmore"><a href="http://www.rainmoe.com/2010/01/10/get-the-files-and-urls-from-flickr/" title="如何抓取Flickr相片集中的图片URL">阅读全文——共3124字</a></span>]]></description>
			<content:encoded><![CDATA[<p>> 最近小邪准备把博客的图片地址都换成 Flickr 上面的图片地址，所以需要用抓取来节省时间。<br />
> 恩恩，纯粹是节省时间，抓取对很多盆友都是不好的事情，小邪的站也被抓过，很杯具。</p>
<p><img src='http://www.rainmoe.com/wp-content/uploads/old/Capture1105.jpg' /></p>
<p>> 那么，在这里小邪就讲解一下如何使用 PHP 的 CURL 函数和正则式抓取 Flickr 的图片。<br />
> 首先用 Curl 带 Cookies 地抓页面代码，然后用正则分离出图片Code，最后得到大尺寸地址。</p>
<p><span id="more-1893"></span>> Rencently, Evlos prepare to change the image urls in my article to the image urls in Flickr.<br />
> So, I think I should use php program to catch urls in Flickr for saving time.<br />
> Um .. Just for saving time, curl isn't a good tools for lots of people.<br />
> Because it can get the whole data in website and make a mirror site for gaining money.<br />
> And I suffered this last month, it's a tragedy.</p>
<p>> First of all, use curl get the html data. We should post some cookies in same time.<br />
> Then use regex to get the code for images. At last, we use image code to get image url.</p>
<p><strong>一. 分析一下地址 Analyse url：</strong></p>
<p><strong>1. 用户地址 User url -</strong></p>
<p>> http://www.flickr.com/photos/46051661@N04<br />
> 比如小邪的用户地址就是这个样子的，很规则，处理有规则的东西是最方便的鸟。</p>
<p>> For example, this is my album url. It's very regular and can easy to deal with it.</p>
<p><strong>2. 相片集地址 Album url -</strong></p>
<p>> http://www.flickr.com/photos/46051661@N04/sets/72157623167782492<br />
> 恩恩，后面是一个 Sets 表示相片集，然后是相片集本身的 Code。<br />
> 小邪喜欢把这些唯一性的字符称为 Code，呵呵，这样比较好说一点儿。</p>
<p>> Um .. It contains a sets code rearward and a user code in der mitte.<br />
> Evlos like called the unique character as code. Haha, it's easily explained.</p>
<p><strong>3. 单张相片地址 Single image url -</strong></p>
<p>> http://www.flickr.com/photos/46051661@N04/4259923860/<br />
> http://www.flickr.com/photos/46051661@N04/4259923860/in/set-72157623167782492<br />
> 嘎嘎，有两种，其实都是一模一样的页面来着，所以咱挑上面的短的。</p>
<p>> <img src='/apps/smiles/icon_smile.gif' alt=':)' class='wp-smiley' /> , Flickr offer two kinds of url, but it will heading us to a same page.<br />
> So, certainly, we choose the shorter url.</p>
<p><strong>4. 单张相片大尺寸地址 Single image url for big size -</strong></p>
<p>> http://www.flickr.com/photos/46051661@N04/4259923860/sizes/o/<br />
> 一般来说小邪的 600px 宽度，高度在 600px 以下的，都用地址 O 来查看全图的。<br />
> http://www.flickr.com/photos/46051661@N04/4259923860/sizes/l/<br />
> 因为 Flickr 不提供大图全图，而 L 是图片尺寸过大后被裁减的地址，所以只好用 L 咯。<br />
> 嘎嘎，还有四个尺寸，依次减小，这样子 - M S T SQ，OK可以开工了。</p>
<p>> In general, my image is limit in 600px and i can get the full size by "o".<br />
> Bacause Flickr limit the size of image by 1024px for free users.<br />
> And "L" is a code for the image exceed 1024px and offer 1024px image.<br />
> Haha, and the remaining four size. Like M S T SQ, so let's beginning. </p>
<p><strong>二. 开始抓取 Begin to catch：</strong></p>
<p><strong>1. 抓取相片 Code 代码 Catch the code of image：</strong></p>
<p>> $sa[0] 里面储存的是相片的 Code，$sa[1] 储存的是相片的标题。<br />
> 而 $sa[2][0] 储存的是相片个数，因为这里是二维数组，小邪不想要 Foreach。<br />
> 虽然双层 Foreach 可以遍历二维数组，不过这里只需要作为两个一维数组就好。</p>
<p>> Put the codes of image in $sa[0]. And put the title of image in $sa[1].<br />
> And put the numbers of images into $sa[2][0], bacause it's 2d array.<br />
> And Evlos don't want to use foreach. Though i can use double-layer foreach.<br />
> I just need to use two 1d array, it's enough.</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
function app_get_set_info($data) {
	$regex = &quot;%\/photos\/46051661@N04\/(\d+)\/in\/set\-\d+\/\&quot;
title=\&quot;([a-z0-9A-Z-_]*)\&quot; class%i&quot;;
	preg_match_all($regex,$data,$save);
	$sa[0] = $save[1];
	$sa[1] = $save[2];
	$sa[2][0] = array_count($save[1]);
	return $sa;
}
</pre>
<p>> $save[1] 是储存第一个括号中匹配内容的数组，而 $save[2] 则是第二个括号的。<br />
> 那么还有一个，是 $save[0]，这个当然就是整串正则式匹配的字符咯，O(∩_∩)O。</p>
<p>> We put the content in firstly bracket into $save[1].<br />
> And the same meaning to content in secendly bracket.<br />
> So, the $save[0] is use to putting the whole content that get by regex.</p>
<p><strong>2. 抓取图片地址：</strong></p>
<p>> 恩，这里整个页面也就一张 JPG 或者 PNG 的大图了（页面元素是 GIF）。<br />
> 所以咱们这样子抓下来。╮(╯▽╰)╭，可怜的 Flickr，被偶剥得半裸了。<br />
> 嘎嘎，差不多就 619 那根全裸男一样了（619 童鞋一定要小邪给他开个裸奔帝国<a target='_blank' rel='nofollow' href='http://liuyijun.com/'>传送门</a>）。</p>
<p>> Um .. The whole image page is just include one jpg or one png url.<br />
> So we can easily get it by regex like the following content.</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
function app_get_ourl($data) {
	$pagelist_regex = &quot;%&lt;img src=\&quot;(.+.jpg)\&quot;%i&quot;;
	preg_match_all($pagelist_regex,$data,$save);
	//print_r($save);
	if (!isset($save[1][0])) {
		$pagelist_regex = &quot;%&lt;img src=\&quot;(.+.png)\&quot;%i&quot;;
		preg_match_all($pagelist_regex,$data,$save);
	}
	return $save[1];
}
</pre>
<p><strong>3. 带 Cookies 的 Curl：</strong></p>
<p>> 因为登陆后在相片集页面可以看到全部照片，所以咱们用 Curl 把  Cookies 传过去。<br />
> 嘎嘎，老样子，大家都喜欢模拟 FF 的访问头部。然后是一些必要的参数。</p>
<p>> Because if we login, we can see the all images in set page.<br />
> So we post the cookies to Flickr, and get the html code.<br />
> Haha .. Same as ever, we like simulate the header of firefox.</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
function app_get_html($url,$cookie='') {
	$curl = curl_init($url);
	$useragent=&quot;Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US;
rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1&quot;;
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt ($curl, CURLOPT_USERAGENT, $useragent);
	if ($cookie&lt;&gt;'') {
		curl_setopt ($curl, CURLOPT_COOKIE, $cookie);
	}
	$data = curl_exec($curl);
	curl_close($curl);
	return $data;
}
// 用法如下，Cookies 信息麻烦自行找到，小邪太懒了╮(╯▽╰)╭。
// The example method like the following content. Please get the cookies by yourself.
app_get_html('http://www.flickr.com/photos/46051661@N04/sets/72157623167782492',
$cookie='cookie_accid=16212532;cookie_epass=816e23c7b24aa6q9f13713e7503de07f;')
</pre>
<p><strong>4. 程序运行过程 The process of running：</strong></p>
<p>> 首先麻烦自行搞到 Flickr 的 Cookies，然后把相片集页面包含的相片 Code 全部抓取来。<br />
> 保存到数据库之类的地方（因为咱们可能会经常超时），一条一条读取数据库中保存的 Code。</p>
<p>> 然后获取图片页面中的 Url，保存到数据库，如果 Url 已经储存就不去抓取了。<br />
> 因为 100% 会出现超时，所以得这样，然后到时候刷新下接着干就好了，嘿嘿。</p>
<p>> 请原谅小邪没有把完整源代码贴出来，因为怕引起 Flickr 官方的注意，虽然可能性不会很大。<br />
> 但是还是小心一点儿为好。而且全部的主要代码已经贴出来了，储存数据库相信你能搞定的。<br />
> 呵呵，时间又到两点多钟了，小邪很想睡觉鸟 Zzzzzzzzzz 晚安喔，小邪这就去把床给上了。</p>
<p>> First of all, get the cookies for yourself. Then get the codes for images.<br />
> Save them into database or something like that. And read data one by one.</p>
<p>> Get the url for single image file and save to db, if it's exist, just skip up.<br />
> Beacuse we will reach the time excceed. So just need to refresh the page.</p>
<p><strong>三. 这难道是水军路过？！：</strong></p>
<p><img src='http://www.rainmoe.com/wp-content/uploads/old/Capture1104.jpg' /></p>
<p>> 截图留念，╮(╯▽╰)╭，人家都是拍照留念，但小邪没事最喜欢截图留念了。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rainmoe.com/2010/01/10/get-the-files-and-urls-from-flickr/feed/</wfw:commentRss>
		<slash:comments>117</slash:comments>
		</item>
		<item>
		<title>制作好一个输出PR图片的API</title>
		<link>http://www.rainmoe.com/2009/12/09/made-a-api-can-output-pr-image/</link>
		<comments>http://www.rainmoe.com/2009/12/09/made-a-api-can-output-pr-image/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 06:35:07 +0000</pubDate>
		<dc:creator>小邪</dc:creator>
				<category><![CDATA[作品 [Work]]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[pr]]></category>

		<guid isPermaLink="false">http://www.evlos.org/?p=1490</guid>
		<description><![CDATA[> ╮(╯▽╰)╭ 昨天白夜三更写的，糊涂地忘记了已经有蛮多网站提供这个功能了，结果就杯具了。

> 不过也没什么，这篇文章刚刚好总结一下 Curl 函数和 File_get_contents 函数的用法。



<span class="readmore"><a href="http://www.rainmoe.com/2009/12/09/made-a-api-can-output-pr-image/" title="制作好一个输出PR图片的API">阅读全文——共2672字</a></span>]]></description>
			<content:encoded><![CDATA[<p>> ╮(╯▽╰)╭ 昨天白夜三更写的，糊涂地忘记了已经有蛮多网站提供这个功能了，结果就杯具了。<br />
> 不过也没什么，这篇文章刚刚好总结一下 Curl 函数和 File_get_contents 函数的用法。</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/old/Capture0704.jpg" /></p>
<p>> 好多服务器为了防采集都禁止 File_get_contents，所以介绍一下俩函数互相替代的方法。<br />
> 话说，昨天给 619 的模板导航栏上加上了分类目录的显示，但我觉得那个模板的函数有点奇怪。</p>
<p>P.s. 呵呵，使用方法如图，作为图片显示即可，有兴趣的童鞋可以调用过去玩玩 O(∩_∩)O。</p>
<p><span id="more-1490"></span>1. <strong>File_get_contents 函数</strong>：</p>
<p><img src="http://www.rainmoe.com/wp-content/uploads/old/Capture0703.jpg" /></p>
<p>> 使用如下的代码可以将变量 $GontenPRURL 里的路径指向的文件读入字符串 $filecontent 中。<br />
> 只要在 Url 中传递参数即可到 Google 获取到 PR 的数值，然后转换为相对的图片文件名称。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
$filecontent = file_get_contents($prurl);
</pre>
<p>> 我简单的使用下面的函数代码过滤了一下 Url 地址。<br />
> 因为没法过滤引号，所以后面再使用 Preg_match 的正则式过滤文件头。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
$evlos_re = array(&quot;\&quot;&quot;,&quot;'&quot;,&quot;!&quot;,&quot;@&quot;,&quot;#&quot;,&quot;$&quot;,&quot;%&quot;,&quot;^&quot;,&quot;&amp;&quot;,&quot;*&quot;,&quot;(&quot;,&quot;)&quot;,&quot;+&quot;,&quot;=&quot;);
$website = str_replace($evlos_re,&quot;&quot;,$website);
</pre>
<p>> 最后再输出一个文件头，再把作为字符串的图片接着输出即可。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
header(&quot;Content-Type: image/jpeg; charset=UTF-8&quot;);
echo $content;
</pre>
<p>2. <strong>Curl 函数</strong>：</p>
<p>> <strong>注意！！</strong>CURLOPT_URL 参数是不支持相对路径的，网上没看到有人提到，害我差点没折腾挂掉。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
$ch1 = curl_init();
$timeout1 = 15;
curl_setopt ($ch1, CURLOPT_URL, $prurl);
curl_setopt ($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch1, CURLOPT_CONNECTTIMEOUT, $timeout1);
$filecontent = curl_exec($ch1);
curl_close($ch1);
</pre>
<p>> 这里就得用那么长的代码来代替上面 File_get_contents 函数的那一行代码了。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
$fixurl = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
$fixurl = str_replace(basename($_SERVER['PHP_SELF']),&quot;&quot;,$fixurl);
$pic = $fixurl.$pic;
</pre>
<p>> $pic 是我的 PR 图片文件，这里通过上面代码把相对路径转换为 Url 路径。<br />
> 最后也差不多，输出一个文件头，再把作为字符串的图片接着输出即可。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
$ch2 = curl_init();
$timeout2 = 15;
curl_setopt ($ch2, CURLOPT_URL, $pic);
curl_setopt ($ch2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch2, CURLOPT_CONNECTTIMEOUT, $timeout2);
$content = curl_exec($ch2);
curl_close($ch2);
</pre>
<p>3. <strong>同行输出日志分类与博客页面列表</strong>：</p>
<p>> 话说原先 Sandbox 只输出博客页面列表的时候 Header.php 只调用了一个函数：</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
&lt;?php sandbox_globalnav() ?&gt;
</pre>
<p>> 然后在主题函数 Functions.php 里面加了一大段这个代码：</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
function sandbox_globalnav() {
	if ( $menu = str_replace( array( &quot;\r&quot;, &quot;\n&quot;, &quot;\t&quot; ), '',
wp_list_pages('title_li=&amp;sort_column=menu_order&amp;echo=0') ) )
		$menu = '&lt;ul&gt;' . $menu . '&lt;/ul&gt;';
	$menu = '&lt;div id=&quot;menu&quot;&gt;' . $menu . &quot;&lt;/div&gt;\n&quot;;
	echo apply_filters( 'globalnav_menu', $menu );
}
</pre>
<p>> 我觉得其实没啥必要的样子，因为下面使用 WP 自带的函数输出一个 Li 列表也是可以达到相同效果的。<br />
> 博客页面是 Wp_list_pages，文章分类是 Wp_list_categories。</p>
<pre class="brush: php; auto-links: false; html-script: false; title: ; notranslate">
&lt;div id=&quot;menu&quot;&gt;
&lt;?php wp_list_categories('title_li=0&amp;orderby=name&amp;show_count=0');
wp_list_pages('title_li=0&amp;sort_column=menu_order'); ?&gt;
&lt;/div&gt;
</pre>
<p>> 然后在 CSS 文件里面把 Li 变成行内元素即可，话说 Li 真是一个神奇的东西。</p>
<pre class="brush: css; auto-links: false; html-script: false; title: ; notranslate">
#access li {
display:inline;
padding-left:8px;
}
</pre>
<p>4. <strong>调用说明页面传送门</strong>：</p>
<p>> <a target="_blank" href="http://tool.evlos.org/primg/">http://tool.evlos.org/primg/</a></p>
<p>5. <strong>欢迎来 Follow 我的 Twitter <a target="_blank" rel="nofollow" href="http://twitter.com/angelsolo">@AngelSolo</a></strong> 。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rainmoe.com/2009/12/09/made-a-api-can-output-pr-image/feed/</wfw:commentRss>
		<slash:comments>71</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using memcached (Feed is rejected)
Page Caching using memcached
Database Caching 1/25 queries in 0.019 seconds using memcached
Object Caching 437/496 objects using memcached

Served from: www.rainmoe.com @ 2012-02-09 16:48:01 -->
