»°ËµPython£¨Î壩¿ªÊ¼Æð·É°É
С°×¶ÔÉϽڿÎÀïµÄ“СÂéȸ”ÐËȤ°»È»£¬ÕûÌì¾ÍÔÚËÞÉáµ·¹Ä¡£Õâ²»£¬¼¸ÌìÏÂÀ´ËûÒѾ¹¥ÏÂÊ®¼¸¸öÍøÕ¾ÁË¡£
С²Ëȴϲ»¶Ò»¸öÈË×øÔÚµçÄÔÅԱߣ¬Öå×Åüͷ£¬ÐÀÉÍ×ÅÕâÒ»ÐÐÐÐ×Ô¼º¿´²»¶®µÄ´úÂë¡£“ÕâЩ×Ö·ûºÃ¹ÖÒìѽ£¡”С²ËÍá×ÅÍ·£¬“ËüΪɶ½ÐÕýÔò±í´ïʽÄØ£¿”
°Ù¶Èһϣ¬ÖÕÓÚÖªµÀ¡£Ð¡²ËÔÚ½ñÌìÉÏ¿ÎÇ°ËƺõÁìÎòµ½ÁËÕýÔò±í´ïʽµÄÕæÚУ¬ÐÄÖÐÇÔϲ£º“½ñÌìÎÒÒªºÃºÃÏÔ°Úһϣ¬¿´Ë»¹ËµÎҲˡ£”
ûÏëµ½£¬½ñÌì´óÅ£ÀÏʦȴ¶ÔÕýÔò±í´ïʽֻ×ÖδÌá¡£
“Ê×ÏÈ£¬ÎÒÃÇÓ¦¸ÃÖªµÀ×Ô¼ºÏëҪʲô£¡”´óÅ£ÀÏʦÏòͬѧÃǽ²µÀ£¬·Â·ðÊÇÔÚÉÏÕÜѧ¿Î£¬“ÎÒÃǵÄÅÀ³æCrawlerÏëÒªµÃµ½Ê²Ã´ÄØ£¿”
CrawlerÖ»ÓÐÒ»¸öÄ¿µÄ£¬ÄǾÍÊÇ»ñÈ¡Ö¸¶¨ÍøÒ³µÄÄÚÈÝ£¬ÌáÈ¡ÀïÃæµÄÁ´½Ó¡£Èç´Ëµ¥Ò»µÄÄ¿µÄÈçºÎʵÏÖÄØ£¿
ÏÖÔÚÎÒÃÇ¿ÉÒÔ²ÂÏëÒ»ÏÂCrawlerµÄ¹¹³É£º
1¡¢Crawler±ØÐëÓÐÒ»¸öÀàÊÇÓÃÀ´ÅÀÐеģ¬ÃûΪCrawl¡£Ê×ÏÈ£¬Ëü½ÓÊÕControl´«µÝµÄÁ½¸ö¶ÓÁУºÒ»¸öÊÇÌṩµØÖ·µÄ£¬Ò»¸öÊÇÓÃÀ´´¢´æCrawlÅÀÐеõ½µÄÐÅÏ¢¡£
2¡¢CrawlerÊÇ»ùÓÚ¶àÏ̵߳ģ¬¸ÃÀà½ÐWorker¡£CrawlÀàÔÚÅÀÐÐʱʹÓÃWorkerʵÏÖ¶àÏ̡߳£WorkerÀà»áÌṩһ¸öÏ̳߳أ¬Ê¹ÅÀÐÐÓÐÐò¡¢Îȶ¨ºÍ¿ìËÙ¡£
3¡¢Crawler±ØÐëÓÐÒ»¸öÀàÀ´¼Ç¼ÍøÒ³µÄÏà¹ØÐÅÏ¢£¬°üÀ¨Á´½Ó¹Øϵ¡¢×¥È¡Ê±¼ä¡¢ÓÅÏȼ¶µÈ£¬ËüÊÇÒ»¸öÊý¾Ý½á¹¹£¬ÊµÏÖËü²¢²»ÄÑ¡£
Ïȱ𼱣¬ÔÚ±àдSparrowµÄCrawler֮ǰ£¬ÓбØÒªÑо¿Ò»ÏÂËüÊÇÈçºÎ±»µ÷Óõġ£
CrawlerÓÐÒ»¸ö¿ØÖÆÆ÷½ÐControl£¬Ëü½«Ò»ÏµÁÐÍøַдµ½Ò»¸ö¶ÓÁÐÀ¹©CrawlerÅÀÐС£Control³õʼ»¯Ò»¸öCrawler£¬¶ÓÁÐÒÔ²ÎÊýµÄÐÎʽ´«µÝ¸øCrawler£¬Crawler¿ªÊ¼¹¤×÷ºó£¬Á¢¼´´Ó¸Ã¶ÓÁÐÀï¶ÁÈëÒ»¸öÍøÖ·£¬½øÐÐһϵÁвÙ×÷ºó·µ»Ø¸ÃÍøÒ³µÄÄÚÈݺÍÍøÒ³ÄÚµÄËùÓÐÁ´½Ó£¬²¢½«ËüÃǷŵ½ÁíÒ»¸ö¶ÓÁÐÀï¡£ÕâÁ½¸ö¶ÓÁж¼ÊÇÓÉControlÌṩµÄ£¬CrawlerÖ»¸ºÔðץȡÍøÒ³ºÍ·ÖÎöÁ´½Ó¡£
ÕâÑù£¬ÎÒÃǾÍÇå³þÁË£ºÈç¹û½«Crawler±È×÷ÊֵĻ°£¬Control¾ÍÊÇ´óÄÔ¡£ControlÓÖÊÇÔõÑùʵÏÖÄØ£¿
ControlÌṩ¸øCrawlerÁ½¸ö¶ÓÁУ¬²¢Æô¶¯Crawler¡£³õʼ»¯CrawlerµÄÓï¾äΪ
crawler=Crawler(request_queue,result_queue)
“Ϊʲô²»ÈÃCrawler×Ô¼ºÑ»·Ö´ÐÐÄØ£¿”С°×ÎʵÀ¡£
ÔÒòÓжþ£º
1¡¢ÎÒÃÇÐèÒª¶ÔÅÀÐкóµÃµ½µÄ½á¹û½øÐд¦Àí£¬Ö»ÄÜÈÃCrawlerÅÀÐÐÎÒÃÇÏëÒªµÄÍøÒ³£¬¶ø²»ÊÇÈÃÅÀ³æÂþÎÞÄ¿µÄµÄÂҹ䡣
2¡¢ÈÃCrawler×Ô¼ºÑ»·ÈÝÒ×Ôì³ÉËÀÑ»·£¬µ¼ÖÂÒç³öÉõÖÁ±ÀÀ£¡£
“ControlºÃ¼òµ
Ïà¹ØÎĵµ£º
1£¬±àдServer.py
import socket
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind(('localhost',8081))
while True:
data,addr=s.recvfrom(1024)
print 'receive:',data,'from',addr
2£¬±àдClient.py
import socket
s=socket.socket(socket.AF_INET,socket.SOC ......
Íò¶ñµÄ±àÂë
С²Ë¶ÔÓÚÀÏʦÉÏÒ»½Ú½²µÄ²»ÊǺÜÃ÷°×£¬ÒòΪûÓÐÒ»±¾ÊéÊǽ«ÎļþÓëwebÒ»Æð½²Êڵģ¬Ëû¾ö¶¨×Ô¼ºÌ½¾¿Ò»ÏÂËüÃÇÖ®¼äµÄ²»Í¬£º
Ê×ÏÈ£¬Ð¡²ËÔÚCÅ̽¨ÁËÒ»¸öÎı¾Îĵµ file.txt,ÊäÈëËĸö×Ö£ºÎÒÊÇС²Ë¡£
È»ºó£¬Ð¡²ËÔÚshellÖÐÁ·Ï°ÆðÀ´£º
>>> file=open("c:\\file.txt","r")
>>> data=file.read()
>> ......
Python£¬¼òµ¥µÄÁ¦Á¿
¶¹°êÍø¶Ô»¥ÁªÍøÓû§À´ËµÊÇÖªÃûµÄWeb 2.0ÉçÇø£¬µ«¶Ô¿ª·¢Õ߶øÑÔ£¬¸üÖØÒªµÄÊÇÒ»¸öÓ¦ÓÃPython´òÔìµÄ·Ç³£³É¹¦µÄWeb 2.0Õ¾µã¡£
Pythonµ®ÉúÒÑÓÐ20ÄêµÄÀúÊ·£¬Ä¿Ç°¹úÄÚµÄPython·¢Õ¹×´¿öÈçºÎ£¿ÓëÆäËûÓïÑÔ£¨Æ½Ì¨£©Ïà±È£¬PythonÓÐÄÄЩÏÔ¶øÒ×¼ûµÄÓŵ㣿¶¹°êÓ¦ÓÃPython½øÐÐWeb¿ª·¢ÓÐÄÄЩ³É¹¦¾Ñé¿ÉÒÔ½è¼ø£¿´ø×ÅÕâЩΠ......
¶ÓÁУº
Óë¶ÑÕ»ÀàËÆ£¬Í¨¹ýpythonµÄÁбíÀàÐÍÀ´ÊµÏÖ£¬²Î¿¼ help(list)
shoplist=['apple','mango','carrot','banana']
print 'I have',len(shoplist),'items to purchase'
print 'these items are:'
for item in shoplist:
print item,
shoplist.append('rice')
print 'my shopping list is now', shoplist
shoplist. ......
python
ÓïÑÔ¸ÅÀÀ
python
½Å±¾¿ÉÒÔ´¦ÀíÍⲿ´«½øÀ´µÄ²ÎÊý ¼´sys.argv[]
£¬argv[]
µÄʹÓÃÓëlinux
ÏÂÏàͬ
python
±¾ÉíÊǽâÊÍÓïÑÔ£¬¿ÉÒÔ¶ÔÊäÈëµÄʽ×ÓÇóÖµ¡£python
Ö§³ÖµÄ¶ÔÏóÈçÕûÊý¶¼ÊÇÁ¢¼´Êý£¬´ËÍâËûÖ§³Ö¸´Êý£¬¼°¶ÔËÄÔòÔËËã½âÊÍ¡£
ptyhon
Ö§³Ö×Ö·û´®£¬·ÅÔÚµ¥/
Ë«ÒýºÅÄÚ£¬×Ö·û´®ÊÇÊý×飬¿ÉÒÔͨ¹ý[i: ......