2011年1月10日 星期一

在命令行下清除IE緩存的方法

這是我們經常使用的方法,如果我們要以命令行的形式來清除IE緩存,如何實現呢?看以下代碼:
借助RunDll32.exe 來運行Internet選項的對應功能。

 比如:

Temporary Internet Files  (Internet臨時文件)

    RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 8

Cookies

    RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 2

History (歷史記錄)

    RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 1

Form Data (表單數據)

    RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 16

Passwords (密碼)

    RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 32

Delete All  (全部刪除)

    RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 255

Delete All - "Also delete files and settings stored by add-ons"

    RunDll32.exe InetCpl.cpl,ClearMyTracksByProcess 4351

 想通過編程方式清除IE緩存, 調用Win32 API函數 ShellExecute 或者 CreateProcess 來執行以上的命令行就可以了。

 例子:

ShellExecute(NULL, _T("open"), _T("rundll32.exe"),  _T("InetCpl.cpl,ClearMyTracksByProcess 4351"), NULL, SW_SHOWNORMAL);

2011年1月1日 星期六

Python 2.5 win32上 安裝SSL1.15

為了Google App Engine 上傳資料時,能有較安全連線的,所以只好裝ssl模組

結果沒想到ssl,有別於其它python 模組,單單使用setup.py install 這樣的指令,無法安裝完成

安裝手續,實在有夠麻煩~~~

上網找了老半天資料,終於把它安裝完畢!
流程如下:
先安裝編譯器MinGW
      下載位置: 網站 http://www.mingw.org/如找不到下載位置,
      直接連結:http://sourceforge.net/projects/mingw/files/

另外還得下載二樣東西:
OpenSSL 安裝完後,將 libgw32c 解壓至該目錄底下

接下來下載SSL1.15
http://pypi.python.org/pypi/ssl/

解壓至任一路徑

修改SSL1.15 的setup.py   gnuwin32_dir路徑


gnuwin32_dir = os.environ.get("GNUWIN32_DIR", r"C:\GnuWin32")

修改完最後就可以開始安裝了
請至SSL1.15 目錄底下 輸入:

python setup.py build -c mingw32 install1


python setup.py build -c mingw32 bdist_wininst


 安裝過程如提示找不到 gcc.exe
程式在 mingw\bin

2010年11月1日 星期一

過濾重複性的資料

我們常會在python 教學文章裡看到
>>> li = ['1', 'd', 'd', 'e', 'a','c']
>>> set(li)
set(['1', 'a', 'c', 'e', 'd'])
>>>
set內定函數幫我們完成過濾資料的動作,
但這樣就像叫一個天才做打掃廁所的工作
,難免無法顯現出它的偉大之處。

2010年10月27日 星期三

去除網頁標籤 tag

# Routine by Micah D. Cochran
# Submitted on 26 Aug 2005
# This routine is allowed to be put under any license Open Source (GPL, BSD, LGPL, etc.) License 
# or any Propriety License. Effectively this routine is in public domain. Please attribute where appropriate.
def strip_ml_tags(in_text):
  """Description: Removes all HTML/XML-like tags from the input text.
  Inputs: s --> string of text
  Outputs: text string without the tags
  
  # doctest unit testing framework
  
  >>> test_text = "Keep this Text  KEEP  123"
  >>> strip_ml_tags(test_text)
  'Keep this Text  KEEP  123'
  """
# convert in_text to a mutable object (e.g. list)
  s_list = list(in_text)
  i,j = 0,0

  while i < len(s_list):
    # iterate until a left-angle bracket is found
    if s_list[i] == '<':
      while s_list[i] != '>':
        # pop everything from the the left-angle bracket until the right-angle bracket
        s_list.pop(i)
      # pops the right-angle bracket, too
s_list.pop(i)
    else:
      i=i+1

  # convert the list back into text
  join_char=''
  return join_char.join(s_list)

def bbToHtmltags(html):
  pass

做留言版、討論區、BLOG、網頁相關時,時常用得到
Removes all HTML/XML-like tags from the input text.
Inputs: s --> string of text
Outputs: text string without the tags
文件說明已寫得很清楚
將網頁語法如  "Keep this Text  KEEP  123"
讓程式讀取後,去除 <> 內的文字,再做輸出成如下:

2010年10月25日 星期一

學習Pyhon 的相關習藉

Python基礎教程 (第2版) 中文高清PDF版
Python學習手冊 第3版(Learning Python, 3rd Edition) 中文版PDF
Python核心編程 (第二版) 高清PDF中文版
Python核心編程 第二版 (Core Python Programming)