2012年8月23日 星期四

Python and MSWord





1)安裝Active Python 
2)執行PythonWin
3)在工具列Tools > COM MakePy utility   出現清單後選擇Microsoft word 14.0 Object Library 進行build
4)開始可於PythonWin使用word物件功能

要使用Python控制MS Word,您需要先安裝win32com套件,這個套件可以到 http://sourceforge.net/projects/pywin32/ 找到。本文假設您已經正確安裝win32com及相關套件,所以將不再針對此部分多做說明。
毫無疑問的,您需要先import win32com模組才能進行Word的控制。
import win32com
from win32com.client import Dispatch, constants
接著,要讓我們的Python程式和MS Word建立起連結。
msword = Dispatch('Word.Application')
用Dispatch()的方式將會啟動MS Word。不過,如果您已經有執行MS Word,則此方式只會與現存的MS Word建立連結。如果您強烈希望能夠有一個新的MS Word程式出現,可用下面的方式:
msword = DispatchEx('Word.Application')
此時您會發現畫面上沒有任何MS Word出現,其實他已經在背後執行了。您可以透過工作管理員來查看是否有一個名為"WINWORD.EXE"的Process。不產生畫面的好處是您可 以在背景來處理您要進行的工作。如果您想要看看到底是不是真的有成功的啟動MS Word,請設定Visible屬性。
msword.Visible = 1 # 1表示要顯示畫面,若為0則不顯示畫面。您可以隨時的更改此屬性。
除了不顯示畫面外,您也許還會希望不要顯示一些警告訊息。此時請設定DisplayAlerts屬性:
msword.DisplayAlerts = 0 # 1表示要顯示訊息,0則會隱藏訊息。
若您真的有把畫面叫出來,您或許會發現此時的畫面上是沒有任何文件開啟的。沒錯!前面的動作只是幫助我們啟動Word並且建立連結,接著我們就要來開啟文件了。我們可以開啟已經存在的文件,或者是新增一個空白文件。
doc  = msword.Documents.Open(FileName="xxx.doc") # 開啟一個名為xxx.doc的文件。
newDoc  = msword.Documents.Add()   # 開啟一個新的文件。
msword.Quit()      # 關閉MS Word.
當然,除了開啟檔案或新建文件,您也可以存檔或者控制這些文件。
docCnt  = msword.Documents.Count  # 取得目前開啟文件的數量。
doc  = msword.Documents[n]   # 取得第n個文件的物件,以便後面的控制。
doc.Activate()     # 將文件設定為主要工作文件。
doc.PrintOut()     # 列印文件
doc.Save()     # 存檔
doc.SaveAs('xxx.doc')    # 另存新檔
doc.Undo(n)     # 回復前n次的動作
取得與文件的聯繫,接著我們可以對他進行編輯。不過,我們要能夠先取得編輯的控制權。透過Document的Range()函式,我們可以取得MS Word的Range物件。
range = doc.Range(0, 0) # 取得Range物件,範圍為文件的最開頭。
range = doc.Range()  # 取得Range物件,範圍為文件的最尾端。
range = doc.Range(doc.Content.Start, doc.Content.End) # 取得Range物件,範圍整份文件。
有了Range物件,我們就可以開始進行編輯了。
range.InsertBefore('在range前面插入的文字')
range.InsertAfter('在range後面插入的文字')
select = range.Select()  # 將range的範圍全部選取。並且取得Selection物件。
如果要設定Style,可以透過range物件的Style屬性來設定。
range.Style = constants.wdStyleHeading1  # 設定style為Heading 1
range.Style = constants.wdStyleHeading2  # 設定style為Heading 2
range.Style = constants.wdStyleHeading3  # 設定style為Heading 3
range.Style = constants.wdStyleHeading4  # 設定style為Heading 4
range.Style = constants.wdStyleHeading5  # 設定style為Heading 5
range.Style = constants.wdStyleHeading6  # 設定style為Heading 6
range.Style = constants.wdStyleHeading7  # 設定style為Heading 7
range.Style = constants.wdStyleHeading8  # 設定style為Heading 8
range.Style = constants.wdStyleHeading9  # 設定style為Heading 9
range.ParagraphFormat.Alignment = constants.wdAlignParagraphLeft # 設定段落為靠左
range.ParagraphFormat.Alignment = constants.wdAlignParagraphRight # 設定段落為靠右
range.ParagraphFormat.Alignment = constants.wdAlignParagraphCenter # 設定段落為置中
range.ParagraphFormat.Alignment = constants.wdAlignParagraphJustify # 設定段落為左右對齊
range.Style.Font.Name = "Arial"   # 設定字型為Arial
range.Style.Font.Name = "Time New Roman" # 設定字型為Time New Roman
range.Style.Font.Name = "標楷體"       # 設定字型為標楷體
range.Style.Font.Color = 0xFF0000  # 設定字型的顏色為Blue
range.Style.Font.Color = 0x00FF00  # 設定字型的顏色為Green
range.Style.Font.Color = 0x0000FF  # 設定字型的顏色為Red
range.Style.Font.Bold = 1   # 設定字型為粗體字
range.Style.Font.Italic = 1   # 設定字型為斜體字
range.Style.Font.Underline = 1   # 為字型加底線
range.Style.Font.Shadow = 1   # 為字型加陰影
range.Style.Font.Outline = 1   # 為字型加外框
如果要插入一個表格,可以用下面的方式來做。
table = doc.Tables.Add(range, 3, 4)   # 新增一個3x4表格
table.Cell(1,1).Range.InsertAfter('Some text')  # 新增文字到cell(1,1)
table.Cell(1,1).Range.Font.Name = "Arial"  # 設定字型為Arial
table.Cell(1,1).Range.Font.Color = 0xFF0000  # 設定字型為blue
table.Rows.Add()     # 新增一個Row
table.Columns.Add()     # 新增一個Column

2012年8月11日 星期六

python decorators三種寫法:decorator with arguments(class),decorator without arguments(class),decorator function with arguments

參考來源:http://www.artima.com/weblogs/viewpost.jsp?thread=240845


Decorators without Arguments(class)

注意事項:
1)decorator的__init__(self,f)必須傳入被修飾的函數f
2)decorator的__call__(self,*args)必須傳入被修飾的函數f的參數
3)執行到@decoratorWithoutArguments 時觸發 decorator的__init__方法
4)呼叫sayHello函數時觸發decorator的__call__方法


class decoratorWithoutArguments(object):

    def __init__(self, f):
        """
        If there are no decorator arguments, the function
        to be decorated is passed to the constructor.
        """
        print "Inside __init__()"
        self.f = f

    def __call__(self, *args):
        """
        The __call__ method is not called until the
        decorated function is called.
        """
        print "Inside __call__()"
        self.f(*args)
        print "After self.f(*args)"

@decoratorWithoutArguments
def sayHello(a1, a2, a3, a4):
    print 'sayHello arguments:', a1, a2, a3, a4

print "After decoration"

print "Preparing to call sayHello()"
sayHello("say", "hello", "argument", "list")
print "After first sayHello() call"
sayHello("a", "different", "set of", "arguments")
print "After second sayHello() call"



執行結果:

Inside __init__()
After decoration
Preparing to call sayHello()
Inside __call__()
sayHello arguments: say hello argument list
After self.f(*args)

After first sayHello() call
Inside __call__()
sayHello arguments: a different set of arguments
After self.f(*args)
After second sayHello() call
________________________________________

Decorators with Arguments(class)

注意事項:
1) decorator的__init__(self,arg1,arg2,arg3)必須傳入decorator需要的參數數量
例如: @decoratorWithArguments("hello", "world", 42) 共有三個參數設定為arg1,arg2,arg3
2) decorator的__call__(self,f)方法必須傳入被修飾的函數f
3)執行到@decoratorWithArguments("hello", "world", 42)時觸發 decorator的__init__方法
4)呼叫sayHello函數時觸發decorator的__call__方法內部定義的wrapped_f(*args)函數



class decoratorWithArguments(object):

    def __init__(self, arg1, arg2, arg3):
        """
        If there are decorator arguments, the function
        to be decorated is not passed to the constructor!
        """
        print "Inside __init__()"
        self.arg1 = arg1
        self.arg2 = arg2
        self.arg3 = arg3

    def __call__(self, f):
        """
        If there are decorator arguments, __call__() is only called
        once, as part of the decoration process! You can only give
        it a single argument, which is the function object.
        """
        print "Inside __call__()"
        def wrapped_f(*args):
            print "Inside wrapped_f()"
            print "Decorator arguments:", self.arg1, self.arg2, self.arg3
            f(*args)
            print "After f(*args)"
        return wrapped_f

@decoratorWithArguments("hello", "world", 42)
def sayHello(a1, a2, a3, a4):
    print 'sayHello arguments:', a1, a2, a3, a4

print "After decoration"

print "Preparing to call sayHello()"
sayHello("say", "hello", "argument", "list")
print "after first sayHello() call"
sayHello("a", "different", "set of", "arguments")
print "after second sayHello() call"


執行結果:


Inside __init__()
Inside __call__()
After decoration
Preparing to call sayHello()
Inside wrapped_f()
Decorator arguments: hello world 42
sayHello arguments: say hello argument list
After f(*args)
after first sayHello() call
Inside wrapped_f()
Decorator arguments: hello world 42
sayHello arguments: a different set of arguments
After f(*args)
after second sayHello() call
_______________________________________________________



Decorator Functions with Decorator Arguments

注意事項:
1)decoratorFunctionWithArguments(arg1, arg2, arg3) 的參數arg1,arg2,arg3為了接收
@decoratorFunctionWithArguments("hello", "world", 42) 的參數"hello", "world", 42
2)decoratorFunctionWithArguments內部的wrap(f)函數在執行敘述行,參數f則是為了接收被修飾函數sayHello,並且wrap(f)在程式執行敘述@decoratorFunctionWithArguments("hello", "world", 42) 時觸發
3)呼叫sayHello("say", "hello", "argument", "list")函數時觸發
decoratorFunctionWithArgument內的wrapped_f(*arg)函數


def decoratorFunctionWithArguments(arg1, arg2, arg3):
    def wrap(f):
        print "Inside wrap()"
        def wrapped_f(*args):
            print "Inside wrapped_f()"
            print "Decorator arguments:", arg1, arg2, arg3
            f(*args)
            print "After f(*args)"
        return wrapped_f
    return wrap

@decoratorFunctionWithArguments("hello", "world", 42)
def sayHello(a1, a2, a3, a4):
    print 'sayHello arguments:', a1, a2, a3, a4

print "After decoration"

print "Preparing to call sayHello()"
sayHello("say", "hello", "argument", "list")
print "after first sayHello() call"
sayHello("a", "different", "set of", "arguments")
print "after second sayHello() call"
執行結果:

with 與 __enter__(),__exit__(),上下文管理器



class Context(object):
    def __init__(self): #物件初始化時執行此方法
        print '__init__()'
    def __enter__(self):#進入with區塊後執行此方法
        print '__enter__()'
        return self
    def __exit__(self, exc_type, exc_val,exc_tb):#離開敘述區塊執行此方法
        print '__exit__()'

with Context():
    print 'Doing work in the context' #敘述區塊



執行結果
>>> 
__init__()
__enter__()
Doing work in the context
__exit__()
_________________________________________________________________

class WithinHello(object):
    def __init__(self, context):
        print 'WithinHello.__init__(%s)' %context
    def do_something(self):
        print 'WithinHello.do_something()'
    def __del__(self):
        print 'WithinHello.__del__'

class Hello(object):
    def __init__(self):
        print 'Hello.__init__()'
    def __enter__(self):
        print 'Hello.__enter__()'
        return WithinHello(self)
    def __exit__(self, exc_type, exc_val,exc_tb):
        print 'Hello.__exit__()'
  
with Hello() as c:
    c.do_something() #此時c為WithinHello的物件





>>>
Hello.__init__()
Hello.__enter__()
WithinHello.__init__(<__main__.Hello object at 0x0000000001CF9FD0>)
WithinHello.do_something()
Hello.__exit__()

_________________________________________________________________

class Context(object):
    def __init__(self, handle_error):
        print '__init__(%s)' % handle_error
        self.handle_error = handle_error
    def __enter__(self):
        print '__enter__()'
        return self
    def __exit__(self, exc_type, exc_val,exc_tb):
        print '__exit__()'
        print ' exc_type =', exc_type
        print ' exc_val  =', exc_val
        print ' exc_tb   =', exc_tb
        return self.handle_error 
        #如果上下文管理器可以處理這個異常,__exit__() 應當返回一個true值來指示不需要傳播這個異       常。如果返回false,就會導致__exit__()返回後重新拋出這個異常。

with Context(True):
    raise RuntimeError('error message handled')
print

with Context(False):
    raise RuntimeError('error message propagated')




>>> 
__init__(True)
__enter__()
__exit__()
 exc_type = <type 'exceptions.RuntimeError'>
 exc_val  = error message handled
 exc_tb   = <traceback object at 0x0000000002AB5B48>

__init__(False)
__enter__()
__exit__()
 exc_type = <type 'exceptions.RuntimeError'>
 exc_val  = error message propagated
 exc_tb   = <traceback object at 0x0000000002AB5D08>

Traceback (most recent call last):
  File "D:/python26/contextErrorHandle.py", line 20, in <module>
    raise RuntimeError('error message propagated')
RuntimeError: error message propagated
_________________________________________________________________

總和所有重要功能的程式碼


#-*- coding:utf8 -*-
#myContextManager.py

class withinContext(object):
    def __init__(self,context):
        #必定需要使用兩個參數self,context
        #其中withinContext中__init__方法的context參數用以接收
        #myContext中__enter__方法的return withinContext(self)敘述式的self參數
        print 'withinContext.__init__(%s)'%context
    def __del__(self):
        print 'withinContext.__del__()'
    def do_something(self):
        print 'withinContext.do_something()'

class myContext(object):
    def __init__(self,handle_error):
        print "myContext.__init__(%s)"%handle_error
        self.handle_error = handle_error
    def __enter__(self):
        print "myContext.__enter__()"
        return withinContext(self)
    def __exit__(self, exc_type, exc_val,exc_tb): #必定需要使用四個參數self,exc_type,exc_val,exc_tb
        print "myContext.__exit__()"
        print "exc_type:",exc_type
        print "exc_val :",exc_val
        print "exc_tb  :",exc_tb
        return self.handle_error #__exit__()方法若回傳True代表不傳播異常 若回傳False則代表傳播異常


with myContext(True) as c:
    c.do_something()
    raise RuntimeError('error message propagated.')



try...except...else...finally... 測試敘述

參考來源:http://www.python.org/dev/peps/pep-0341/


try:
     <測試敘述>
except:
     <如果測試敘述發生異常則執行此區塊>
else:
     <如果測試敘述未發生異常則執行此區塊>
finally:
     <不論測試敘述是否發生異常皆執行此ㄑㄩ>



++++++++++++++++++++++++++++++++++
try:
raise ValueError
    
except:
print 'EXCP_BLOCK'
else:
print 'ELSE_BLOCK'
finally:
print 'FINAL_BLOCK'


=================== RESTART ==========================
>>> 
EXCP_BLOCK
FINAL_BLOCK



try:
print 'TRY_BLOCK'
    
except:
print 'EXCP_BLOCK'
else:
print 'ELSE_BLOCK'
finally:
print 'FINAL_BLOCK'


======= RESTART ================================
>>> 
TRY_BLOCK
ELSE_BLOCK
FINAL_BLOCK

2012年8月7日 星期二

threading 初步使用

#簡單使用多線程
import threading
import datetime

#Inherit the threading class to use multi-threading function

class ThreadClass(threading.Thread):
    def run(self):
          #executed 'run' method when the instance 't' start by method t.start()
        now = datetime.datetime.now()
        print "%s says Hello world at time: %s\n" % (self.getName(),datetime.datetime.now())

for i in range(5):
    t = ThreadClass()
    t.start()

>>> 
Thread-1 says Hello world at time: 2012-08-08 00:59:37.715000
Thread-3 says Hello world at time: 2012-08-08 00:59:37.717000
Thread-2 says Hello world at time: 2012-08-08 00:59:37.716000
Thread-4 says Hello world at time: 2012-08-08 00:59:37.718000
Thread-5 says Hello world at time: 2012-08-08 00:59:37.718000

#模仿真實使用線程的結果

import threading
import datetime
import time
import random

class myThread(threading.Thread):
    def run(self):
        now = datetime.datetime.now()
        print 'Execution time:{0} {1}\n'.format(datetime.datetime.now(),self.getName())
        #print 'ThreadName    :{0}\n'.format(self.getName())
        result = []
        for i in range(1,1000):
            result.append(i)
        time.sleep(random.randint(1,3)) # 模擬各線程所耗費的處理時間
        print "ThreadName    :{0} DONE..\n".format(self.getName())


for eachthread in range(1,5):
    t = myThread()
    t.start()
    time.sleep(1)



>>>
Execution time:2012-08-08 01:00:59.385000 Thread-1

Execution time:2012-08-08 01:01:00.385000 Thread-2

ThreadName    :Thread-1 DONE..

Execution time:2012-08-08 01:01:01.385000 Thread-3

ThreadName    :Thread-2 DONE..

Execution time:2012-08-08 01:01:02.385000 Thread-4

ThreadName    :Thread-3 DONE..

ThreadName    :Thread-4 DONE.. 

python函數的可變參數的prototype




#函數的prototype(加上* 和 ** 符號)

def functionName(para,*tup_para,**dic_para):
    print para
    for each in tup_para:
        print each
    for k,v in dic_para.items():
        print k,v

##使用時須加上*和**符號解析之

>>> functionName('stayhigh',*(1,2,3),**{'k1':'v1','k2':'v2'})
stayhigh
1
2
3
k2 v2
k1 v1
##若不使用*和**符號
則將tup_para與dic_para當成tuple的元素並解析之

>>>functionName('stayhigh',(1,2,3),{'k1':'v1','k2':'v2'})
#此時(1,2,3),{'k1':'v1','k2':'v2'}皆為tup_para的元素

stayhigh
(1, 2, 3)
{'k2': 'v2', 'k1': 'v1'}



#若要使用參數默認值,則函數原形為(不須加上*和 **符號)


def functionName(para='dname',tup_para=(1,2),dic_para={'k1':'v1'}):
    print para
    for each in tup_para:
        print each
    for k,v in dic_para.items():
        print k,v


>>> functionName()
dname
1
2
k1 v1

>>> functionName('stayhigh',(3,4),{'mykey':'myvalue'})
stayhigh
3
4
mykey myvalue


#最常見的使用方式
def fstandard(arg='stayhigh',*args,**kwargs):

print 'arg:',arg
print 'args:',args
print 'kwargs:',kwargs




>>> fstandard(1,2,3,mykey1='myvalue1',mykey2='myvalue2')
arg: 1
args: (2, 3)
kwargs: {'mykey2': 'myvalue2', 'mykey1': 'myvalue1'}


使用apply函數的優點:
參考至:http://www.cnpythoner.com/post/90.html
。做pys60时UI构造比较麻烦,有apply的话,用一个列表来构造整个程序的数个界面就不是问题了。主要还是参数的给出非常灵活,可以把已有的一个列表或者字典直接丢过去。


#python 2.5以上版本,對於apply函數的建議

apply(object[, args[, kwargs]]) -> value

Call a callable object with positional arguments taken from the tuple args,
and keyword arguments taken from the optional dictionary kwargs.
Note that classes are callable, as are instances with a __call__() method.

Deprecated since release 2.3. Instead, use the extended call syntax:
    function(*args, **keywords).


#使用kwargs需要注意的小細節

>>> def dfunc(**kwargs):
for k,v in kwargs.items():
print k,'->',v

#使用a=1,b=2的參數形式傳遞
>>> dfunc(a=1,b=2) 
a -> 1
b -> 2
#使用**{'a':1,'b':2}的參數形式傳遞
>>> dfunc(**{'a':1,'b':2})
a -> 1
b -> 2

2012年8月3日 星期五

ACM程式練習題

參考來源: http://chchwy.blogspot.tw/2008/09/acm_30.html
=解題提示=
UVa官方論壇:
全世界UVa討論的集散地,當你題目解不出來時,第一件事就該來這裡搜尋該題目的討論串,通常會找到很多好心人提供的測資跟提示。
Methods to Solve
全世界最大的UVa解題提示網站,收錄的題目數量很多,品質也不錯。
Algorismist
這是一個關於演算法的維基網站,也有收錄 UVa 的解題提示,如果你有能力可以參與編輯條目,讓它變得更好。
UVa Toolkit
一般來講UVa題目頁上的範例測資都太簡單,聊勝於無。而 UVa Toolkit 這工具恰好補足了這方面的缺憾,你可以餵給它任何測資,並取得正確的對應輸出,對釐清題意很有幫助。
uHunt
非常非常好用的 UVa 解題工具網頁,可以很輕鬆的搜尋題目,安排自己解題的方向,瀏覽自己過去的解題紀錄等等。


=題目中譯=
Lucky貓
著名的ACM題目中譯網,及解題提示。
Lucky貓Mirror站
同上,有難度提示。
ACM中譯
少量題目中譯。
ZeroJudge
ZeroJudge是非常優秀的國產程式解題網,裡面有一區專門收錄UVa題目中譯。


=算法教學=
DJWS的網路日誌
資源豐富的網站,整理了很多的算法教學,以及各種ACM競賽的資料。
C語言考古題 & C的解題
大量題目教學
Art of Programming Contest for uva
淺顯的ACM入門書,免費線上版。
NACOW
對岸關於程式設計與解題的wiki
Infinite Loop
提供許多教學及ACM Tips, Sources。

=API Reference=
Cplusplus.com
簡潔清楚的C/C++標準函式參考手冊,範例碼清楚實用,值得看看,我自己把這兒當後花園逛了。

=題目列表=
ACM熱題排行榜
芭樂題排行榜,有哪些熱門題你還沒解過呢XD

=討論論壇=
NPSC補完計畫
針對NPSC的解題網站
OIBH
對岸關於資訊奧林匹亞競賽討論的論壇
algogeeks
Google group about algorithms.

=解題強者=這部分網站就請各位審慎參觀了,大部分ACMer的程式碼都寫得不太好讀。
ACM's PARADISE
大量題目解答、測資及答案(現在似乎收山了),作者會在PTT C_AND_CPP版出沒。
給你Idle的權利
ACM強者的個人站,不少題目解答碼
心如止水
350+題目解答,有基本的題目分類。
Bluefintuna的Blog
DD的USACO征程
200+ UVa解答,以及基本的資料結構程式範例。
主打USACO的Blog
Robert Anderson's Blog
200+ UVa解答
Nothing is Everything
少量UVa Source,品質不錯
小璋丸UVa解答 Java版
JAVA解題的強者。
摸索C語言
英雄出少年,解題高手,以Zero Judge為主。
朱色虫居
少量UVa解答,品質不錯
YT's ACM
高手解題夥伴YT的站
Kaipeng Liu's Column
大量UVa解答
Eddy's Blog
來自對岸的強者,解題不分國家呀。
iakasT's blog 
蠻厲害的日本人

ACM程式考題練習(有難度分類)
http://luckycat.kshs.kh.edu.tw/

2012年8月1日 星期三

URL extraction using python urldigger.py

參考資料:http://code.google.com/p/urldigger/


EXAMPLES:
GET URLS FROM A GOOGLE SEARCH TERM
ecasbas@cipher:~/proyectos/urldigger$ python urldigger.py -g urldigger
http://urldigger.com/
http://code.google.com/p/urldigger/
http://code.google.com/p/urldigger/updates/list
http://sniptools.com/vault/urldigger
http://www.urldigger.com/articles/81/asshole-of-the-year-nominee-abu-abdullah.html
----OUTPUT CUT-----
GET URLS FROM TWITTER HOT WORDS
ecasbas@cipher:~/proyectos/urldigger$ python urldigger.py -W
http://itunes.apple.com/us/album/now-playing/id193558513
http://sourceforge.net/projects/nnplaying/
http://vivapinkfloyd.blogspot.com/2008/06/how-to-make-simple-amarok-now-playing.html
http://vivapinkfloyd.blogspot.com/2008/05/how-to-make-simple-amarok-now-playing.html
----OUTPUT CUT-----
GET URLS FROM CRAWLING YOUR SITE
ecasbas@cipher:~/proyectos/urldigger$ python urldigger.py -c http://www.nasa.gov
http://www.nasa.gov/about/career/index.html
http://www.nasa.gov/about/highlights/bolden_bio.html
http://www.nasa.gov/about/highlights/garver_bio.html
http://www.nasa.gov/about/highlights/leadership_gallery.html
http://www.nasa.gov/about/org_index.html
http://www.nasa.gov/about/sites/index.html
http://www.nasa.gov/astronauts
----OUTPUT CUT-----
SHOW HOT URLS FROM ALEXA
ecasbas@cipher:~/proyectos/urldigger$ python urldigger.py -H
http://realestate.yahoo.com/promo/most-expensive-us-small-town-sagaponack-ny.html
http://www.realsimple.com/home-organizing/new-uses-for-old-things/new-uses-penny-00000000027632/index.html?xid=yahoobuzz-rs-012210&xid=yahoo
http://movies.yahoo.com/news/usmovies.thehollywoodreporter.com/forbes-lists-biggest-flops-last-five-years
http://health.yahoo.com/experts/drmao/23125/soup-therapy-detoxify-lose-weight-and-boost-immunity/
http://answers.yahoo.com/question/index?qid=20100111162407AATTvcJ
----OUTPUT CUT-----
BRUTE FORCE MODE
ecasbas@cipher:~/proyectos/urldigger$ python urldigger.py -b > allurls.txt
Be careful, currently the output is about 18917 urls.
DETECT SPAM OR SPURIOUS CODE IN YOUR SITE
ecasbas@cipher:~/proyectos/urldigger$ python urldigger.py -g "site:uclm.es"
Looking for SPAM in........http://publicaciones.uclm.es/
*Suspicious SPAM!!!-----> http://publicaciones.uclm.es/* [(viagra)]
Looking for SPAM in........http://www.uclm.es/to/cdeporte/pdf/PublicacionesProfesorado.pdf
Looking for SPAM in........http://www.uclm.es/cr/caminos/publicaciones/publicaciones.html
Looking for SPAM in........http://www.uclm.es/profesorado/ricardo/Publicaciones.htm
Looking for SPAM in........http://publicaciones.uclm.es/index.php?action=module&path_module=modules_Product_index
*Suspicious SPAM!!!-----> http://publicaciones.uclm.es/index.php?action=module&path_module=modules_Product_index*
Looking for SPAM in........http://www.uclm.es/PROFESORADO/mydiaz/_private/PUBLICACIONES.pdf
NOTE: Functional code only available thorough the source in the repository.


另外撰寫過濾urldigger.py輸出行的程式碼,比如過濾出結尾為.jpg的URL
並將每行URL輸出,接著利用wget 下載所有過濾後的連結。

python urldigger.py -c http://exawarosu.net/archives/7356470.html|python isPicurl.py |while read line; do wget -P /home/stayhigh/mypics  $line; done