KPBroswer最小化瀏覽器程序
KPBroswer是一個基于QtWebKit的最小化瀏覽器程序,通過被第三方程序調(diào)用,
能實現(xiàn)對復雜頁面加載后數(shù)據(jù)(例如,復雜Ajax、數(shù)據(jù)加密)的抓取,支持屏幕截圖。
KP是“鯤鵬”二字的拼音首字母。
適用場景:
頁面數(shù)據(jù)動態(tài)加載(例如,Ajax過程過于復雜,分析成本太高);
數(shù)據(jù)加密(客戶端JS解密,解密算法難以獲取或難以用其它語言實現(xiàn));
屏幕截圖;
跨平臺的抓取方案;
依賴庫:
PyQt4
Ubuntu下安裝方法:sudo apt-get install python-qt4
Windows下安裝方法:在這里下載二進制安裝包直接安裝http://www.riverbankcomputing.co.uk/software/pyqt/download/
調(diào)用方法:
若在Linux終端下運行,需要安裝Xvfb。Ubuntu下安裝方法:apt-get install xvfb xfonts-base xfonts-75dpi xfonts-100dpi xfonts-wqy
調(diào)用舉例(Linux):xvfb-run python KPBroswer.py http://www.site-digger.com --flags=redice --output="page.html" --screenshot="sitedigger.jpg"
調(diào)用舉例(Windows):python KPBroswer.py http://www.site-digger.com --flags=redice --output="page.html" --screenshot="sitedigger.jpg"
Usage: KPBroswer.py [options]
Options:
-h, --help show this help message and exit
-p PROXY, --proxy=PROXY
Proxy to use.
-t TIMEOUT, --timeout=TIMEOUT
The timeout time of loading page.
-f FLAGS, --flags=FLAGS
Flags need to wait for. Semicolon can be used as a
eperator.
-w WAIT_TIMEOUT, --wait_timeout=WAIT_TIMEOUT
The timeout time of waitting for flags.
-g, --gui Whether to show the broswer GUI.
-o OUTPUT, --output=OUTPUT
The output filename.
-s SCREENSHOT, --screenshot=SCREENSHOT
If the value is not empty, take a screenshot and save
it here.
注意:
Linux下不要忘記安裝相關(guān)字體庫,否則截圖中的漢字將會是亂碼,如下圖site-digger-font-problem.jpg所示。
安裝后,就正常了,如圖site-digger.jpg所示。
示例:
sample.py文件為一個Python以外部程序方式調(diào)用KPBroswer.py的示例,其它語言的調(diào)用可以參考其實現(xiàn)。
