cookies.sqlite → cookies.txt

Linux下,將Firefox的cookies.sqlite轉換成curl可以接受的cookie格式:


sqlite3 -separator $'\t' cookies.sqlite \
    'select host, "TRUE", path, case isSecure when 0 then "FALSE" else "TRUE" end, expiry, name, value from moz_cookies' > cookies.txt


Reference:

Install PIL on Linux Mint 11 x64

Install PIL on Linux Mint 11 x64

# prepare:

  • libjpeg62-dev
  • zlib1g-dev
  • libfreetype6-dev
  • liblcms1-dev
  • python-dev

 

# edit setup.py

TCL_ROOT = None
JPEG_ROOT = '/usr/lib/x86_64-linux-gnu', '/usr/include' # libjpeg and libpng are here.
ZLIB_ROOT = JPEG_ROOT
TIFF_ROOT = None
FREETYPE_ROOT = JPEG_ROOT
LCMS_ROOT = None

 

# build & test & install

  • python setup.py build_ext -i
  • python selftest.py
  • sudo python setup.py install
Reference:

python setup.py uninstall?



setup.py沒有uninstall選項,所以這部份需要手動移除。
移除安裝:
  1. python setup.py install --record log
  2. sudo rm -rf $(cat log)
    or
    cat log | xargs sudo rm -rf
Reference:

curl POST之後遇到302重導的問題


curl POST資料到主機後,主機回應302時,如果只是用-L參數會得不到想要的資料。
這時候要加上--post302參數。

curl -L --post302 {POST data} {url}

aria2 note

aria2 note

速度真的很快,比wget快很多。有空再來試試看XML-RPC那部份。
  • --load-cookies 讀取cookie,可以直接把Firefox的cookies.sqlite丟進來使用。
  • -U 設定user-agent
  • -j 設定同時下載數目
  • -i 輸入檔案,在設定URL的同時,還可以設定額外的參數。 詳細參照http://aria2.sourceforge.net/aria2c.1.html#_input_file
  • -j 設定同時下載的數目
  • -l logfile
  • --log-level=LEVEL (debug, info, notice, warn or error. Default: debug)

As of 1.10.0 release, aria2 uses 1 connection per host by default and has 20MiB segment size restriction.
(1 connection/host, 20MiB segment)

aria2 是把巨鎚,我試著用1.10.9版,抓取1753個頁面的資料。
結果,在3分鐘內發送完所有的request, 並抓完約158MiB的資料量。每個頁面大小約80~100KiB。
比起wget這速度是快很多。光是1 connection就有這麼快的速度,如果再多幾個connection?
想想就蠻恐怖的。或許,在使用aria2抓取網頁的時候,要好好想想怎麼利用這工具,才不會變成黑名單吧>"<。
Reference:

[Python] BeautifulSoup note

  • BeautifulSoup(html, fromEncoding='...', smartQuotesTo='html')
    • fromEncoding: 用在非UTF-8編碼的網頁。有些網頁像Getchu的網頁有時候也會有問題,這不是BeautifulSoup本身的問題,只是網站標示的編碼跟實際上 使用的編碼不同。保險的作法是用iconv轉成utf-8再丟給BeautifulSoup處理。
    • smartQuotesTo='html': HTML/XML Entity轉換
  • .find(text='abc')
    HTML: <a href='..'>hello</a> ex: soup.find('a', text='hello') ==> hello #只會傳回標籤內的文字,不會傳回Tag物件

feh

feh速度快,只可惜1.0版不支援讀取ZIP/RAR檔案。不知道未來有沒有可能支援?
不過feh我認為最好的地方是,可以自訂按鍵對應指令(雖然數量只有9個>"<)

usage:

  • -g 設定視窗大小以 'widthxheight'的方式
  • -i 縮圖模式(Index Mode)
    -E or --thumb-height 設定縮圖高度
    -y or --thumb-width 設定縮圖寬度
    --index-dim bool 顯示/隱藏影像大小
    --index-name bool 顯示/隱藏影像檔名
    --index-size bool 顯示/隱藏影像檔案大小
    -o 輸出檔名
  • -t 類似於Index mode, 點選縮圖會出現另外的視窗顯示
  • -S or --sort 排序,除了name跟filename其他都需要配合-p參數
    • name
    • filename
    • width
    • height
    • pixes
    • size
  • --info 執行指令並將結果顯示在feh視窗下方
    feh --info="identify -format '%f: %wx%h' %f" -g 640x480 . #執行ImageMagick取得影像大小
  • --action 自訂每張圖片執行指令
  • --action[1-9] 按下數字鍵1~9,所對應的指令(只能用F1下方的數字鍵)
    feh -g 640x480 --action1="cp %f ~/" # 按下數字鍵1時將檔案複製到使用者家目錄下
    feh -g 640x480 --action2='rm %f" # 按下數字鍵2時將檔案刪除