Tuesday, August 7, 2012

Sikuli demo - 取得網頁資料

sikuli logo

Sikuli這東西剛出現時,引起網路上一陣喧然大波,至少那時候我看的不少網站都有介紹到這個算是革命性的軟體,簡單來說,Sikuli就是個可以辨識圖片的automate工具,能辨識圖片就表示看的懂螢幕,所以你跟畫面上的互動Sikuli都能做得到,詳細介紹可以去看Sikuli官網,我這就不多說了。

之前用到Sikuli script我都是玩玩,直到最近才有用在工作上,累積了不少心得與經驗,但是這東西又有點難分享,實際上我是寫了一個模組化的GUI測試功能,會每天定時的去測試各個瀏覽器對於我們Project的相容性、是否正常,然後整合結果到一封信裡寄出來。但是這些東西因為牽扯到工作,所以沒辦法直接拿來分享,所以就亂做一個取巴哈熱門版面資料的Sikuli script,寫起來不長,就下面的20行。


sikuli_demo

簡單解釋一下:
Line 1 : 引用strftime,等等轉日期到字串要用
Line 2~5: 開chrome然後連到巴哈指定頁面
Line 6~7: 等頁面讀完,開檢視元素
Line 8~12: 找到放排名的table,複製起來
Line 12~15: 開notepad把資料貼上去
Line 16: 等notepad一下
Line 17~18: 存成帶有日期的文字檔
Line 19~20: 把chrome跟notepad關掉


下面是實際跑起來的樣子,我錄成影片比較看的懂


如果要寫程式去做上面那些事,我想應該會花不少功夫,但是使用Sikuli script很快就可以解決,這樣就可以省很多時間,只要去處理抓下來的檔案就好,少很多東西要做。

基本上Sikuli可以做到很多事,看怎麼運用而已,Sikuli's Official Blog裡有很多神人的作品,可以參考看看。然後Sikuli語法跟Python是差不多的,一些比較detail的東西就直接看文件吧。

4 comments:

  1. Questa scarpa alexander mcqueenb replica è di qualità perfetta e comoda da indossare, alexander mcqueen scarpe italy quindi puoi indossare questa scarpa durante il viaggio e non ti stancherà i piedi. Consiglio questo sito ai miei buoni amici,kids alexander mcqueen scarpe italy sono molto felici di acquistare scarpe alexander mcqueen così economiche

    ReplyDelete
  2. The quality of this replica Moncler dress is perfect and comfortable to wear,replica moncler jackets so you can wear this outfit without travelling.replica moncler blazers I recommend this website to my good friends, they are very happy to be able to buy such cheap Moncler clothes

    ReplyDelete
  3. Welcome to Soccer Shop - The Best Wholesale cheap Soccer Jerseys on the Internet. cheap willian JerseysWe specialise in the best quality and cheap soccer jerseys.

    ReplyDelete
  4. Rolex offers a wide range of models ranging from professional to classic watches to suit any wrist.replica watches UK Explore the Rolex collection by selecting your favourite models, materials, bezels, cheap replica rolex watchesdials and bracelets to find the watch that was made for you.

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...