十月 18
這支程式主要是用來練習 Perl 的,功能面倒是其次。
功能:
輸入一 Flickr 照片頁面網址,便會提取出文章標題、頁面連結、圖片網址、作者名稱、標籤,並嵌入CSS和HTML碼中。
原本要用 WWW::Mechanize 模組,但抓取頁面回來的編碼好像會爛掉,只好改用 system call cURL 來抓。另外正規表示式的部份邊翻書邊找用的到的功能。
下一階段目標就是改寫成可以自動發佈到 blogger 上。
Screenshot:
(以 http://www.flickr.com/photos/lauct/3701237852/ 為例)
ps. 寫的很爛,其實不太好意思放上來 XD
FlickrFilter下載:Flickr2bps (32)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | #!/usr/bin/env perl # flickr.pl # Created by Chun-Ting Liu on 2009-10-17 require 5.008008; #use warnings; #use strict; my $title, $imgurl, $username, $canonical, $tag, $comment; print "請輸入Flickr頁面網址,以利抽取資訊:\n"; my $url = <STDIN>; chomp( $url ); print "\n擷取網頁中...\n"; system ("curl $url | head -n 300 > flickr.temp.htm"); print "擷取完畢。\n\n"; open FH, ("flickr.temp.htm") or die "開啟檔案失敗: $!"; while (<FH>) { chomp; if(/meta name="title"/) { s/<meta name="title" content="//; s/\" \/>//; $title = $_; print "Title:\n$title\n\n"; } if(/link rel="image_src"/) { s/ <link rel="image_src" href="//; s/\" \/>//; s/_m.jpg/.jpg/; $imgurl = $_; print "Image:\n$imgurl\n\n"; } if(/geo_possessed_username/) { s/var geo_possessed_username = '//; s/[;]//; s/\\'s\'//; $username = $_; print "User:\n$username\n\n"; } if(/link rel="canonical"/) { s/ <link rel="canonical" href="//; s/\" \/>//; $canonical = $_; print "PhotoPageURL:\n$canonical\n\n"; } #<meta name="description" content="galileo09"> if(/meta name="description"/) { s/ <meta name="description" content="//; s/">//; $comment = $_; print "Comment:\n$comment\n\n"; } #tag keywords if(/meta name="keywords"/) { s/ <meta name="keywords" content="//; s/\">//; if (/photography, digital photography, cameraphones, camera, hobby photography, photo, digital camera, compactflash, smartmedia, cameras, canon, nikon, olympus, fujifilm, video/) { s/photography, digital photography, cameraphones, camera, hobby photography, photo, digital camera, compactflash, smartmedia, cameras, canon, nikon, olympus, fujifilm, video//; } if (/, photography, photos, photo/) { s/, photography, photos, photo//; } $keyword = $_; } } close FH; system ("rm flickr.temp.htm"); print "HTML code:\n\n"; print '<style type="text/css">.flickr-photo { }.flickr-frame { float: center; text-align: center; margin-left: 15px; margin-bottom: 15px; }.flickr-caption { font-size: 0.8em; margin-top: 0px; }</style><div class="flickr-frame"> <img src="'.$imgurl.'" class="flickr-photo" style="border: solid 6px #fff;"/><br /><span class="flickr-caption"><a href="'.$url.'">'.$title.'</a>, originally uploaded by '.$username.'.<br />This photo was picked by <a href="http://beautypapers.blogspot.com/">beautypapers</a>.</span></div><p class="flickr-yourcomment">'.$comment.'</p>'."\n\n\n"; print "Tag:\n$keyword\n\n"; |
溫故知新
載入中…
歷史上的今天..
- 林志玲 - 蘇菲雅婚紗 - 2006
- 老媽,您真內行 - 2005








最新回應