ÀûÓÃPythonץȡºÍ½âÎöÍøÒ³(ÉÏ)
¶ÔËÑË÷ÒýÇæ¡¢ÎļþË÷Òý¡¢Îĵµ×ª»»¡¢Êý¾Ý¼ìË÷¡¢Õ¾µã±¸·Ý»òǨÒƵÈÓ¦ÓóÌÐòÀ´Ëµ£¬¾³£Óõ½¶ÔÍøÒ³(¼´HTMLÎļþ)µÄ½âÎö´¦Àí¡£ÊÂʵÉÏ£¬Í¨¹ýPythonÓïÑÔÌṩµÄ¸÷ÖÖÄ£¿é£¬ÎÒÃÇÎÞÐè½èÖúWeb·þÎñÆ÷
»ò
ÕßWebä¯ÀÀÆ÷¾ÍÄܹ»½âÎöºÍ´¦ÀíHTMLÎĵµ¡£±¾ÎĽ«Ïêϸ½éÉÜÈçºÎÀûÓÃPythonץȡºÍ½âÎöÍøÒ³¡£Ê×ÏÈ£¬ÎÒÃǽéÉÜÒ»¸ö¿ÉÒÔ°ïÖú¼ò»¯´ò¿ªÎ»ÓÚ±¾µØºÍWeb
ÉϵÄHTMLÎĵµµÄPythonÄ£¿é£¬È»ºó£¬ÎÒÃÇÂÛÊöÈçºÎʹÓÃPythonÄ£¿éÀ´Ñ¸ËÙ½âÎöÔÚHTMLÎļþÖеÄÊý¾Ý£¬´Ó¶ø´¦ÀíÌض¨µÄÄÚÈÝ£¬ÈçÁ´½Ó¡¢Í¼ÏñºÍ
CookieµÈ¡£×îºó£¬ÎÒÃÇ»á¸ø³öÒ»¸ö¹æÕûHTMLÎļþµÄ¸ñʽ±êÇ©µÄÀý×Ó£¬Í¨¹ýÕâ¸öÀý×ÓÄú»á·¢ÏÖʹÓÃpython´¦ÀíHTMLÎļþµÄÄÚÈÝÊǷdz£¼òµ¥µÄÒ»¼þ
ÊÂÇé¡£
¡¡¡¡Ò»¡¢½âÎöURL
¡¡¡¡Í¨¹ýPythonËù´øµÄurlparseÄ£¿é£¬ÎÒÃÇÄܹ»ÇáËɵذÑURL·Ö½â³ÉÔª¼þ£¬Ö®ºó£¬»¹Äܽ«ÕâЩԪ¼þÖØÐÂ×é×°³ÉÒ»¸öURL¡£µ±ÎÒÃÇ´¦ÀíHTML ÎĵµµÄʱºò£¬ÕâÏÄÜÊǷdz£·½±ãµÄ¡£
¡¡¡¡
import
urlparse
¡¡¡¡parsedTuple
=
urlparse.urlparse(
¡¡¡¡
"
http://www.google.com/search?
¡¡¡¡hl
=
en
&
q
=
urlparse
&
btnG
=
Google
+
Search
"
)
¡¡¡¡unparsedURL
=
urlparse.urlunparse((URLscheme, \
¡¡¡¡URLlocation, URLpath,
''
,
''
,
''
))
¡¡¡¡newURL
=
urlparse.urljoin(unparsedURL,
¡¡¡¡
"
/module-urllib2/request-objects.html
"
)
¡¡
¡¡º¯Êýurlparse(urlstring [, default_scheme [,
allow_fragments]])µÄ×÷ÓÃÊǽ«URL·Ö½â³É²»Í¬µÄ×é³É²¿·Ö£¬Ëü´ÓurlstringÖÐÈ¡µÃURL£¬²¢·µ»ØÔª×é (scheme,
netloc, path, parameters, query, fragment)¡£×¢Ò⣬·µ»ØµÄÕâ¸öÔª×é·Ç³£ÓÐÓã¬ÀýÈç¿ÉÒÔÓÃÀ´È·¶¨ÍøÂç
ÐÒé(HTTP¡¢FTPµÈµÈ )¡¢·þÎñÆ÷
µØÖ·¡¢Îļþ·¾¶£¬µÈµÈ¡£
¡¡
¡¡º¯Êýurlunparse(tuple)µÄ×÷ÓÃÊǽ«URLµÄ×é¼þ×°Åä³ÉÒ»¸öURL£¬Ëü½ÓÊÕÔª×é(scheme, netloc, path,
parameters, query, fragment)ºó£¬»áÖØÐÂ×é³ÉÒ»¸ö¾ßÓÐÕýÈ·¸ñʽµÄURL£¬ÒԱ㹩PythonµÄÆäËûHTML½âÎöÄ£¿éʹÓá£
¡¡
¡¡º¯Êýurljoin(base, url [, allow_fragments])
µÄ×÷ÓÃÊÇÆ´½ÓURL£¬ËüÒÔµÚÒ»¸ö²ÎÊý×÷ΪÆä»ùµØÖ·£¬È»ºóÓëµÚ¶þ¸ö²ÎÊýÖеÄÏà¶ÔµØÖ·Ïà½áºÏ×é³ÉÒ»¸ö¾ø¶ÔURLµØÖ·¡£º¯ÊýurljoinÔÚͨ¹ýΪURL»ùµØÖ·
¸½¼ÓеÄÎļþÃûµÄ·½Ê½À´´¦ÀíͬһλÖô¦µÄÈô¸ÉÎļþµÄʱºò¸ñÍâÓÐÓá£ÐèҪעÒâµÄÊÇ£¬Èç¹û»ùµØÖ·²¢·ÇÒÔ×Ö·û/½áβµÄ»°£¬ÄÇôURL»ùµØÖ·×îÓұ߲¿·Ö¾Í»á±»Õâ¸ö
Ïà¶Ô·¾¶ËùÌæ»»¡£±ÈÈ磬URLµÄ»ùµ
Ïà¹ØÎĵµ£º
PythonÖÐ×Ö·û´®±»¶¨ÒåΪÒýºÅÖ®¼äµÄ×Ö·û¼¯ºÏ¡£PythonÖ§³ÖʹÓóɶԵĵ¥ÒýºÅ»òË«ÒýºÅ£¬ÈýÒýºÅ°üº¬µÄ×Ö·û´®¡£
ʹÓÃË÷Òý²Ù×÷·û([])ºÍÇÐƬ²Ù×÷·û([:])¿ÉÒԵõ½×Ó×Ö·û´®¡£×Ö·û´®ÓÐÆäÌØÓеÄË÷Òý¹æÔò£ºµÚÒ»¸ö×Ö·ûµÄË÷ÒýÊÇ£°
£¬×îºóÒ»¸ö×Ö·ûµÄË÷ÒýÊÇ-1¡£
¼ÓºÅ(+)ÓÃÓÚ×Ö·û´®Á¬½ÓÔËË㣬ÐǺÅ(*)ÔòÓÃÓÚ×Ö·û´®Öظ´¡£ÈçÏÂÀý£º
pystr = " ......
ÄÜÕûÀí´ó²¿·ÖÎÞÓÃÎļþ
#!/usr/bin/python
#syscleaner.py
import os
import os.path
#delete files and directory recursively
def itedel(dir):
print('in dir :'+dir)
for doc in os.listdir(dir):
try:
if(os.path.isdir(doc)):
itedel(dir+'\\'+doc)
......
1. 9.7 ÕýÔò±í´ïʽÓë re Ä£¿é
Ò»¸öÕýÔò±í´ïʽ¾ÍÊÇÒ»¸öÓÃÀ´±íʾijÖÖģʽµÄ×Ö·û´®¡£ËüÄÜ°ïÖúÄã·½±ãµÄ¼ì²éÒ»¸ö×Ö·û´®ÊÇ·ñÓëijÖÖģʽƥÅä¡£
re Ä£¿éʹ Python ÓïÑÔÓµÓÐÈ«²¿µÄÕýÔò±í´ïʽ¹¦ÄÜ¡£ compile º¯Êý¸ù¾ÝÒ»¸öģʽ×Ö·û´®ºÍ¿ÉÑ¡µÄ±êÖ¾²ÎÊýÉú³ÉÒ»¸öÕýÔò±í´ïʽ¶ÔÏ󡣸öÔÏóÓµÓÐһϵÁз½·¨ÓÃÓÚÕýÔò±í´ïʽƥÅäºÍÌæ»»¡£ re Ä£ ......
ʹÓÃpython.vimʹpython´úÂë¸ßÁÁ
http://www.vim.org/scripts/script.php?script_id=790
ʹÓÃ
Pydiction²å¼þʹvimÔö¼Ótab´úÂëÌáʾ¹¦ÄÜ
http://www.vim.org/scripts/script.php?script_id=850
¾ßÌå°²×°·½·¨¿ÉÒÔ²ÎÕÕ°ïÖú»òÕßREADME£¬ÒòΪ°æ±¾±ä»¯»áµ¼Ö°²×°·½·¨ÉϲúÉú²îÒì
±à¼~/.vimrcÎļþÔö¼ÓÏÂÃæÑ¡Ïî
set nu Ôö¼ÓÐÐ ......
Ò»¡¢Ê²Ã´ÊÇPython£¿
¶ÔÓÚÕâÖÖÎÊÌâÎÒÃÇÀ´°Ù¶ÈһϾͿÉÒÔÁË¡£
“PythonÊÇÒ»ÖÖ¿ª·ÅÔ´´úÂëµÄ½Å±¾±à³ÌÓïÑÔ£¬ÕâÖֽű¾ÓïÑÔÌرðÇ¿µ÷¿ª·¢ËٶȺʹúÂëµÄÇåÎú³Ì¶È¡£Ëü¿ÉÒÔÓÃÀ´¿ª·¢¸÷ÖÖ³ÌÐò£¬´Ó¼òµ¥µÄ½Å±¾ÈÎÎñµ½¸´Ôӵġ¢ÃæÏò¶ÔÏóµÄÓ¦ÓóÌÐò¶¼ÓдóÏÔÉíÊֵĵط½¡£Python»¹±»µ±×÷Ò»ÖÖÈëÃųÌÐòÔ±×îÊʺÏÕÆÎÕµÄÓÅÐãÓïÑÔ£¬ÒòΪËüÃâ·Ñ¡¢Ã ......