http://blog.binchen.org/posts/how-to-do-htmljavascript-repl-read-eval-print-loop-with-no-server-set-up-2.html
關於直接 telnet 然後下達指令的部分,這個網頁的解說很詳細,值得參考
2014年8月14日 星期四
perl one-liner以mozrepl查詢firefox瀏覽器資料--以btkitty網頁內容的表格為例
perl -MNet::Telnet -e "$t=new Net::Telnet();$t->open(Host=>'localhost', Port=>4242);$t-> print('content.document.body.innerHTML');while(1){my $data=$t->get(Timeout=>1);print $data;}" | perl -MData::Dumper -MHTML::TreeBuilder::XPath -MHTML::Element -e "my $crlf=\"\n\";$string = do { local($/); <> }; $tree= HTML::TreeBuilder::XPath-> new_from_content($string);my $pages=$tree->findnodes( '//div[@class=\'pagination\']/span') -> [0]->as_text;$pages=~s/[^0-9]//g;my $table=$tree->findnodes( '//div[@class=\'list\']')->[0]; foreach my $row($table->findnodes('//dl[not(@class=\'banner\')]')){my @cells=$row-> content_list();print join('',map{$_->as_text.'|||' if ref($_)} $cells[1]-> content_list()),$crlf,$cells[1]->dump;my @dec=$cells[1]->descendants();print $dec[0] ,$crlf;print join('|||',map{$_->as_text if ref($_)}$cells[0]->content_list()),$crlf;}print $crlf;" >btkitty.txt存到 btkitty.txt 再打開來看,因為原始網頁編碼是 utf8 ,直接輸出到螢幕會有亂碼,轉碼對非繁中語系還是會出問題。
windows平台上的doskey
http://forum.twbts.com/thread-10210-1-1.html
我覺得最有用的是 doskey /history>abc.txt
這個指令可以把之前打的指令存到abc.txt中,看是要做成批次檔,還是貼到網頁上,都非常好用
我覺得最有用的是 doskey /history>abc.txt
這個指令可以把之前打的指令存到abc.txt中,看是要做成批次檔,還是貼到網頁上,都非常好用
2014年8月13日 星期三
sourceforge上有趣的語音辨識專案
http://cmusphinx.sourceforge.net/
這是 cmu 所開發的
http://julius.sourceforge.jp/en_index.php
這是京都大學所開發的
中文的專案目前還沒有,不過網路上現在有這麼多影片和字幕,拿來訓練這些辨識引擎應該很方便才對…
這是 cmu 所開發的
http://julius.sourceforge.jp/en_index.php
這是京都大學所開發的
中文的專案目前還沒有,不過網路上現在有這麼多影片和字幕,拿來訓練這些辨識引擎應該很方便才對…
github上有趣的 python 專案
perl one-liner以mozrepl查詢firefox瀏覽器資料--以海盜灣(the pirate bay)網頁內容的表格為例
在此將問題分解為三個部分,分別是
- 取得網頁原始碼。結果為一個檔案;generic
- 取得表格原始碼。結果為列導向的多筆資料,特定分隔符號分隔各欄位;site specific
- 對表格原始碼進行後處理,得到想要的資料,排列成所需的格式;requirement specific
1.取得網頁原始碼。使用 mozrepl 來取得原始碼有許多好處,可以忽略登入的問題,不需處理解壓縮的問題,可以處理 javascript ,各種好處。
perl -MNet::Telnet -e "$t=new Net::Telnet();$t->open(Host=>'localhost', Port=>4242); $t-> print ('content.document.body.innerHTML');while(1){my $data=$t->get(Timeout=>1);print $data;}"
這個程式碼片斷會取得顯示中頁面的原始碼
2.表格原始碼的取得。列舉的方式有 map 或 foreach ,兩者我都列出來,供大家參考 。範例頁面為 http://thepiratebay.se/top/all ,其中列有當日前100名資源的資料。為方便觀察,將結果存到 top100.txt。
perl -MNet::Telnet -e "$t=new Net::Telnet();$t->open(Host=>'localhost', Port=>4242);$t->print('content.document.body.innerHTML');while(1){my $data=$t->get(Timeout=>1);print $data;}"| perl -MData::Dumper -MHTML::TreeBuilder::XPath -MHTML::Element -e "$string = do { local($/); <> }; $tree= HTML::TreeBuilder::XPath-> new_from_content($string);my @results=$tree->findnodes( '/html/body/div[@id=\"content\"]/div[@id=\"main-content\"]/table[@id=\"searchResult\"]/tbody') ;foreach my $table(@results){foreach my $row($table->findnodes('.//tr')){my @cells=$row-> findnodes ('.//td'); print join(\"\n\", map{ $_->as_HTML if ref($_)} $cells[1]-> content_list() ), \"\n\";foreach $acell($cells[1]->content_list()){print $acell->as_text.\"\n\" if ref($acell) ;};print $cells[0]->string_value,\"\n\";}print \"\n\";}" > top100.txt
這個程式片斷前半就是抓網頁原始碼的程式,使用 pipe 將結果做過濾
3.to be continued...
2014年8月12日 星期二
perl one-liner以mozrepl查詢firefox瀏覽器資料--以標題為例
perl -MNet::Telnet -MEncode -e "$t=new Net::Telnet(Dump_Log=>\*STDOUT);$t->open (Host=>'localhost', Port=>4242);$t->print('document.title');while(1){my $data=$t->get (Timeout=>1);print encode('big5',decode('utf8',$data));}"
- 要先裝好mozrepl
- 本例在win8上測試正常
- encode的部分視所在環境而調整,在ubuntu上完全可以拿掉
- 或許你會說,幹麻不用 WWW::Mechanize::Firefox 就好了,問題是它在windows上沒有人 port 啊 XD
- 嘗試一下 WWW::Mechanize::Firefox 的 porting 。下載並解壓後,執行 perl makefile.pl ,出現以下錯誤訊息:
Warning: prerequisite HTML::Selector::XPath 0 not found.
Warning: prerequisite MozRepl::RemoteObject 0.31 not found.
Warning: prerequisite Object::Import 0 not found. - 打開 ppm ,安裝上述三個套件。
- MozRepl::RemoteObject 可能無法用 ppm 安裝,此時下載該套件的 tar.gz 檔,解壓後進入子目錄執行 perl Makefile.PL ,再將 lib 子目錄中的所有內容複製到 C:\Perl64\site\lib (視perl 安裝在何處而定)
- 補充一下,ppm上沒有的套件,在不需 c compiler 的情況下,可以下達 cpan WWW::Mechanize::Firefox 安裝
訂閱:
文章 (Atom)