ÕýÔò±í´ïʽÓëpython
ÔÚPythonÖÐÓÐÒ»¸ö·Ç³£ÖØÒªÒ²·Ç³£ºÃÓõÄÄ£¿ére£¬ÔÚimport reºó£¬¾ÍÄܹ»ÔÚPythonÖÐʹÓÃÕýÔò±í´ïʽ£¬Ô´ÓÚ´Ë´ÎÏîĿҪÓÃÕýÔò±í´ïʽ¶Ôhtml´úÂëÌáȡһ¶¨µÄ×Ö·û£¬ËùÒÔÔÚÕâÒ²¾ÍÓÃЩСÀý×ÓÀ´ÊìϤһÏÂÕýÔò±í´ïʽ
ÏÖÔÚ¾ÍÓÃ×î¼òµ¥µÄÀý×Ó
import re
s='<title>http://www.baidu.com</title>'
print re.findall(r'<\w+>(.+)</',s)
ÔËÐкó½á¹ûΪ
>>>
['http:\\www.baidu.com']
Õâ¸öÏà¶ÔÀ´Ëµ»¹ÊDZȽϼòµ¥µÄ£¬µ«ÊÇÕâ¸öÕýÔò±í´ïʽ»¹ÊÇÓбȽ϶àµÄÎÊÌâ
1¶ÔÓڱȽϸ´ÔÓµÄ×Ö·û´®£¬±ÈÈçǶÌ×Á˱êÇ©µÄ×Ö·û´®£¬¾ÍûÓа취ÁË£¬ÒòΪֻÄܹ»ÅжÏ×îÍâÒ»²ãµÄ<></>±ê¼Ç¶øÒÑ
2ÊÇÕâ¸öÊÇÅжϾßÓÐÀàËÆ<></>±ê¼ÇµÄ×Ö·û´®£¬¶ÔÓÚʵ¼ÊµÄhtmlÖеÄÌáÈ¡£¬»¹ÊÇÒª¼ÓÉϾßÌåµÄÖµ£¬±ÈÈçÊÇtitle£¬»¹ÊÇhead
import re
s='<head><title>http:\\www.baidu.com</title></head>'
print re.findall(r'title>(.+)</title',s)
ÔËÐкóµÃµ½
>>>
['http:\\www.baidu.com']
ËäÈ»ÔÚÕâ¸ö±È½Ï¼òµ¥µÄ´úÂëÖÐÎÒÃǽâ¾öÁËÉÏÊöÁ½¸öÎÊÌ⣬µ«ÊÇÕë¶ÔhtmlÖиü¼Ó¸´ÔӵĴúÂ룬ÎÒ¾õµÃ»¹ÊÇ»áÓкܶàµÄÎÊÌâ
²»¹ý½ñÌìÒ²¾ÍÊǼòµ¥µÄÊìϤһÏÂÕýÔò±í´ïʽ£¬ËùÒÔÒ²¾Í²»ÔÙÈ¥ÉîÈëÑо¿£¬¾¹ý¶ÓÔ±µÄÌÖÂÛºóÔÚ̽ÌÖ½â¾öÎÊÌâµÄ·½°¸
ÏÂÃæ¸ø³öÒ»¸öÅжÏÓÊÏ䵨ַÊÇ·ñºÏ·¨µÄÕýÔò±í´ïʽ
ÓÊÏäÖ÷Òª°üÀ¨@ºÍ.£¬ËùÒÔÔÚÅжϵÄʱºòÒ²Ö»Ðè¼ÙÈçÕâÁ½¸öÌõ¼þ¾Í¿ÉÒÔÁË
import re
s='zhuangruln@gmail.com zhuangasdsad@126.com zhusdandsai@adsd'
print re.findall(r'(\w+@\w+\.\w+)',s)
ÔËÐнá¹û
['zhuangruln@gmail.com', 'zhuangasdsad@126.com']
>>>
Ïà¹ØÎĵµ£º
#!/Library/Frameworks/Python.framework/Versions/2.5/bin/python
# encoding: utf-8
import sys, time
import thread
SLEEP_TIME = 0.0001
def run_benchmark(n, m):
# print(">> Python 2.5.1, stackless 3.1b3 here (N=%d, M=%d)!\n" % (n, m))
lock ......
²Ù×÷ϵͳ£ºlinux debian 4.0£¬ python°æ±¾2.5
s1:°²×°python2.5-dev¡£ÒòΪPython.hÊÇÔÚdev°üÖвÅÓС£
test@debian:~/test_python_c$ aptitude search python2.5-dev
p python2.5-dev - Header files and a static library for Python.
test@debian:~/test_python_c$ sudo aptitude install python2 ......
·¢ÐÅÈË: TRAD (GFans), ÐÅÇø: NLP
±ê Ìâ: Ô´´£ºÊ¹ÓÃpythonµ÷ÓüÆËãËù·Ö´Ê
·¢ÐÅÕ¾: ˮľÉçÇø (Mon Nov 23 13:30:46 2009), Õ¾ÄÚ
´úÂëºÜ¼òµ¥£¬µ«ÎÒ×Ô¼ºÃþË÷ÁËÒ»ÏÂÎç,·¢³öÀ´¹²ÏíÒ»ÏÂ
°ÑÕâ¸öÎļþͬICTALAS30.DLL £¬DATAÎļþ¼Ð£¬Configure.xm l·ÅÔÚͬһ¸öĿ¼Ï¼´¿É¡£
python´úÂë
#coding:gb2312
from cty ......
Ê×ÏÈÒª¸ãÇå³þ£¬×Ö·û´®ÔÚPythonÄÚ²¿µÄ±íʾÊÇunicode±àÂ룬Òò´Ë£¬ÔÚ×ö±àÂëת»»Ê±£¬Í¨³£ÐèÒªÒÔunicode×÷ΪÖмä±àÂ룬¼´ÏȽ«ÆäËû±àÂëµÄ×Ö·û´®½âÂ루decode£©³Éunicode£¬ÔÙ´Óunicode±àÂ루encode£©³ÉÁíÒ»ÖÖ±àÂë¡£
decodeµÄ×÷ÓÃÊǽ«ÆäËû±àÂëµÄ×Ö·û´®×ª»»³Éunicode±àÂ룬Èçstr1.decode('gb2312')£¬±íʾ½«gb2312±àÂëµÄ×Ö· ......