Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

PythonÕýÔò±í´ïʽ

ÕýÔò±í´ïʽÊǸöħ¹í£¬Ò²ÊǸöÌìʹ¡£ÔÚÄãûÓÐÕÆÎÕËü֮ǰ£¬ËüÊÇħ¹í£¬ÔÚÄãÕÆÎÕËüºó£¬ËüÊÇÌìʹ£¬µ«ÊÇ£¬Ê±
²»Ê±»¹ÊÇÒªÌø³öÀ´£¬¸øÄãµ÷Ƥµ·µ°Ò»·¬¡£


Ò»¸öÕýÔò±í´ïʽ¾ÍÊÇÓÉÆÕͨ×Ö·ûÒÔ¼°ÌØÊâ×Ö·û×é³ÉµÄÎÄ×Öģʽ£¬¸ÃģʽÃèÊöÔÚ²éÕÒÎÄ×ÖÖ÷Ìåʱ´ý
Æ¥ÅäµÄÒ»¸ö»ò¶à¸ö×Ö·û´®¡£ÕýÔò±í´ïʽ×÷Ϊһ¸öÄ£°å£¬½«Ä³¸ö×Ö·ûģʽÓëËùËÑË÷µÄ×Ö·û´®½øÐÐÆ¥Å䣬²¢ÄÜÌáÈ¡³öÆ¥ÅäµÄ½á¹û¡£ËüÊÇËÑË÷¡¢Ìæ»»ºÍ½âÎö¸´ÔÓ×Ö·ûģʽµÄ
Ò»ÖÖÇ¿´ó¶ø±ê×¼µÄ·½·¨¡£

ÕýÔò±í´ïʽÓÐ×Å×ÜÌ广·¶µÄÒ»Ì×Óï·¨£¬µ«Êǵ½Á˸÷ÖÖÓïÑÔÖУ¬ÓÖ»áÓÐʹÓÃÉϵÄÉÔ΢²»Í¬£¬Ö÷ÒªÊDZí´ïʽµÄϸ
΢Óï·¨±í´ï£¬»¹ÓÐÓïÑÔµÄÆ¥ÅäÀàºÍ·½·¨µÄ²»Í¬¡£

PythonµÄËùÓÐÀà¿â¶¼ÔÚre°üÖУ¬ºÍjava
1.4ÒÔºóµÄ²»Í¬£¬StringµÄ¸÷¸ö·½·¨£¬findºÍreplace¶¼²»×Ô×öÖ÷ÕŵÄȥʹÓÃÕýÔò±í´ïʽ£¬¶øÊÇʹÓüòµ¥µÄ×Ö·û´®·½Ê½¡£ÕâµãÎұȽÏÐÀÉÍ£¬ÓÐʱ
ºòÖ»ÊÇ×öһЩ¼òµ¥µÄÌæ»»£¬²»ÒªÅªÕýÔò±í´ïʽÕâôÂé·³£¬Ò²ÈÃÐÂÊÖÃÇÃþ²»×ű±£¬Ìæ»»Á½¸ö×Ö·û¾ÍҪȥÁ˽âÕýÔò±í´ïʽÕâô¿äÕÅ¡£

¹¤¾ß
   
PythonÓÐÒ»¸ö·Ç³£ºÃµÄÕýÔò±í´ïʽ¸¨Öúµ÷ÊÔ¹¤¾ß£ºKodos¡£ÓÐWindows°æ±¾£¬ÌṩÁ˶ÔÕýÔò±í´ïʽµÄ·½±ãµÄʵʱµ÷ÊÔ¹¦ÄÜ£¬½¨ÒéѧϰÕýÔò±í´ïʽǰ
Ò»¶¨ÒªÏÂÔØ£º
     http://kodos.sourceforge.net/
   
 
Ó¦Óó¡¾°£º
 ×ª»»urlΪ·¾¶Ãû
import
 re
articleUrl =
"http://pp.sohu.com/yule/photoview-44789795.html#44789795"
path =
re.sub("http://|https://", "", articleUrl)
path =
re.sub("[?&.=#-]", "_", path)
path
   
'pp_sohu_com/yule/photoview_44789795_html_44789795'
  
      
²ÉÓÃÕâÖÖÌæ»»·½Ê½£¬ËæÊ±·¢ÏÖurlÖÐÓÐзǷ¨×Ö·û£¬Ìí¼Óµ½[]ÖоͿÉÒÔÁË¡£[]±íʾ×Ö·û¼¯£¬ÔÚ[]ÆäÖеÄÈÎÒâ×Ö·û£¬¶¼»á±»Æ¥Åäµ½
      
 
2.  ÌáÈ¡htmlÒ³ÃæÖÐimg±êÇ©µÄsrcÊôÐÔ
    
import
 re
    
import
 urllib
    imgSrcPattern 
=
 r
'''
<img\s*src\s*="?(\S+)"?
'''
    
    pageUrl 
=
 
'
http://pp.sohu.com/yule/photoview-44789


Ïà¹ØÎĵµ£º

»ù±¾Êý¾Ý½á¹¹µÄpythonʵÏÖ ¶ÑÕ»

ǰÑÔ£º
×î½üÓÖÏëѧϰpython,ÓÖÏëÈ¥ÎÂϰһÏÂËã·¨£¬ÓÚÊǾÍÏë³öÁËÕâ¸öÁ½²»ÎóµÄ·½·¨,^_^
¶ÑÕ»£º
ʹÓÃpythonµÄÁбí½á¹¹£¬ÏêÇé¿ÉÒԲ鿴help(list)
#Filename: stack.py
shoplist=['apple','mango','carrot','banana']
shoplist.append('rice')
popitem=shoplist[-1]
del shoplist[-1]
print 'the popitem is',popitem
......

Ïòpython¿¿½ü

  ÕÛÌÚ¼ÆËã»ú£¬±»¼ÆËã»úÕÛÌÚ£¬Ç°Ç°ºóºóÒ²ÓÐÊ®¼¸Äê¡£
  ×î¿É±¯µÄÊǾÓȻһÎÞËù³É£¬ËäÈ»½ö½ö³öÓÚÐËȤ£¬²¢ÎÞ¹¤×÷֮ѹÁ¦£¬µ«ÊÇÕâÖÖ´ìÕÛ¸ÐȷʵÊÇʵ´òʵµÄ¡£
  ÒѾ­¼Ç²»ÆðÊÇÄÄÒ»ÌìÁË£¬ºÃÏñͻȻ¾ÍÖªµÀÁËpythonµÄ´æÔÚ£¬´Ó×î³õµÄ²»¾­Ò⣬µ½Ô½À´Ô½Ï²°®£¬ÎÒÒ»²½²½µÄÏòpython¿¿½ü¡£
ÎÒϲ»¶Python£¬ÕâÊÇÒ»¸öÊÂʵ£¬ÎÒ׫´ ......

»°ËµPython£¨ËÄ£©»¶Ó­Ð¡Âéȸ

С°×ÊǸö΢ÈíÃÔ£¬ËûµÄżÏñÊDZȶû´óÊ壬ԭÒòµ±È»ÊǵØÇòÈ˶¼ÖªµÀÀ²¡£´ó¶þµÄʱºò£¬ËûµÄ“ê¡Ñ§¼Æ»®”ÔøÒ»¶ÈµÃ³Ñ£¬Ô­ÒòÊÇËû¹Ò¿ÆÌ«¶à¡£µ±È»£¬´óÈýÐÂѧÆÚ¿ªÊ¼µÄʱºò£¬Ãæ¶Ô¹«ÖÚÖÊÒÉ£¬Ð¡°×Õ¾ÔÚÒÎ×ÓÉÏ£¬Ïñ¼«ÁË¡¶´óÄÚÃÜ̽ÁãÁã·¢¡·ÀïµÄÎ÷ÃÅ´µÑ©£º“ÊÀ½çÊ׸»±È²»Ò»¶¨Óжà³öÉ«£¬ÕâÖ»²»¹ýÊÇÄãÃÇÕâЩÐǶ·ÊÐÃñÒ»ÏáÇéÔ¸µÄÏë·¨° ......

python ±Ê¼Ç for loop and extend, append

list.append(item)
list.extend(sequence)
http://docs.python.org/tutorial/datastructures.html
http://docs.python.org/library/functions.html Õ⼸Ìì¿´Ò»ÏÂ
python howto
¶÷¡£python documentation ȷʵºÜºÃºÜÇ¿´ó°¡£¡
list.append(x)Add an item to the end of the list; equivalent to a[len(a):]&n ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ