2012年9月8日 星期六

Firefox《ADD-ONS》

DD-ONS 非常棒。Firefox 與其說是瀏覽器,不如說作業平台。



小根已經裝上 SQLite Manager、Firebug,請大家多多支持 Firefox,當然,小根還是用 Chrome 當瀏覽器,或許是習慣吧。



剛試玩一下,蠻可怕的,re-scrap 計劃於是必須產生。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE></TITLE>
<META http-equiv=Content-Type content="text/html; charset=big5">
<META content="MSHTML 6.00.2800.1170" name=GENERATOR></HEAD>
<BODY><BR><BR><BR><BR><BR><BR>
<center><table width="80%" border="0" cellspacing="8" cellpadding="0">
    <tr>
      <td><font size=8 color=BLUE><center>系統流量大,請稍後再查詢!</center></font></td>
    </tr>
</table></center>
</BODY></HTML>



只好開大絕,總之,sourcing.py 如下

import os
import re
import time

class Sourcing():
    def source(self, seed_file, dest_dir):
        assert os.path.isfile(seed_file)
        [ self._wget(seed.strip(), dest_dir) for seed in open(seed_file) ]       

    def _wget(self, seed, dest_dir):
        wget_image = os.path.abspath('../../thirdparty/wget/wget.exe')
        assert os.path.isfile(wget_image)
       
        dest_file = os.path.join(dest_dir, re.compile('https?://').sub('', seed))
        dest_file_dir = os.path.dirname(dest_file)
        if not os.path.exists(dest_file_dir):
            os.makedirs(dest_file_dir)
        wget_cmdline = '''%s \"%s\" --waitretry=10 -P %s''' % (wget_image, seed, dest_file_dir)

        os.system(wget_cmdline)
        time.sleep(5)



整段程式就 time.sleep(5) 睡五秒最重要。class Sourcing 最重要的就是 seed_file,這個請自行用 Firebug 研究,很有趣的。

沒有留言:

張貼留言