Python¿âÏê½âÖ®ÍøÂç(2)
×òÌìÊÔÁËÏÂÓÃHTMLParserÀàÀ´½âÎöÍøÒ³£¬¿É·¢ÏÖ½á¹û²¢²»ÀíÏë¡£²»¹ÜÔõô˵£¬ÏÈдϹý³Ì£¬Ï£ÍûºóÀ´ÈËÄÜÔÚ´Ë»ù´¡ÉϽâ¾öÎÒËùÓöµ½µÄÎÊÌâ¡£
дÁË2Ì×½â¾ö·½°¸£¬µ±È»Õâ2Ì×Ö»ÄܶÔÌض¨ÍøÕ¾ÓÐЧ¡£ÎÒÕâÀïÖ÷Ҫ˵Ã÷϶ÔBBCÖ÷Ò³www.bbc.co.ukºÍ¶ÔÍøÒ×www.163.comµÄ½âÎö¡£
¶ÔÓÚBBC£º
ÕâÌ×Òª¼òµ¥µÃ¶à£¬¿ÉÄÜÊǸÃÍøÒ³µÄ±àÂë±È½Ï±ê×¼°É
import html.parser
import urllib.request
class parseHtml(html.parser.HTMLParser):
def handle_starttag(self, tag, attrs):
print("Encountered a {} start tag".format(tag))
def handle_endtag(self, tag):
print("Encountered a {} end tag".format(tag))
def handle_charref(self,name):
print("charref")
def handle_entityref(self,name):
print("endtiyref")
def handle_data(self,data):
print("data")
def handle_comment(self,data):
print("comment")
def handle_decl(self,decl):
print("decl")
def handle_pi(self,decl):
print("pi")
#´ÓÕâÀ↑ʼ¿´Æð£¬ÉÏÃæÄǸö¼Ì³ÐºÜ¼òµ¥£¬È«²¿ÖØÔظ¸ÀຯÊý
#ÒÔ¶þ½øÖÆдµÄ·½Ê½´æ´¢BBCÍøÒ³£¬ÕâÊÇÉÏƪÄÚÈÝ(http://blog.csdn.net/xiadasong007/archive/2009/09/03/4516683.aspx),²»×¸Êö
file=open("bbc.html",'wb') #it's 'wb',not 'w'
url=urllib.request.urlopen("http://www.bbc.co.uk/")
while(1):
line=url.readline()
if len(line)==0:
break
file.write(line)
#Éú³ÉÒ»¸ö¶ÔÏó
pht=parseHtml()
#¶ÔÓÚÕâ¸öÍøÕ¾£¬ÎÒʹÓÃ'utf-8'´ò¿ª£¬·ñÔò»á³ö´í£¬ÆäËûÍøÕ¾¿ÉÄܾͲ»ÐèÒª£¬utf-8ÊÇUNICODE±àÂë
file=open("bbc.html",encoding='utf-8',mode='r')
#´¦ÀíÍøÒ³£¬feed
while(1):
line=
Ïà¹ØÎĵµ£º
Ô´´úÂëÏÂÔØ£ºÏÂÔصØÖ·ÔÚÕâÀï
# 034
class Person:
def __init__(self, name):
self.name = name # ÕâÒ»¾äÖеÚÒ»¸önameÊÇÀàÖаüº¬µÄÓò£¬µÚ¶þ¸önameÊÇ´«½øÀ´µÄ²ÎÊý
# end of def
def sayHello(self):
print 'Hello!'
# end of def
# end of class
p = Person('Ning')
print p.nam ......
Ê×ÏÈÊÇÏÂÔØpython3£¬ÏÖÔÚµÄ×î¸ß°æ±¾ÊÇ3.1.1
for linux¡£
ÎҵķÅÖ÷¾¶ÊÇ/home/pythonÏ·ÅÖÃPython-3.1.1.tgz,Ö´ÐÐÒÔÏÂϵÁвÙ×÷£º
1.½âѹ£ºtar zxvf Python-3.1.1.tgz----Éú³É½âѹ°üPython-3.1.1
2.ת»»µ½Python-3.1.1·¾¶Ï£¬Ö´ÐÐ./configure
3.make
4.make install
ÔÚrehl5ÖÐÒѾĬÈÏ°²×°ÁËpython2.4,ËùÒÔÒª×öÈçÏ ......
python stringºÍPyQtµÄQStringµÄÇø±ð ÒÔÏÂÔÚPython2.6ºÍPyQt4.4.4 for
Python2,6»·¾³ÏÂÌÖÂÛ£º PythonÖÐÓÐÁ½ÖÖÓйØ×Ö·ûµÄÀàÐÍ£ºPython string objectºÍPython Unicode
object¡£Ö÷ҪʹÓÃPython string object½øÐÐÊý¾ÝÊäÈëÊä³ö¡£ PyQtÖÐÓëÖ®Ïà¶ÔÓ¦µÄ×Ö·ûÓйØÀà
python stringºÍPyQtµÄQStringµÄÇø±ð
ÒÔÏÂÔÚPython2.6ºÍPyQt4 ......
ż¶û×ö¸ö¼òµ¥µÄWEB·þÎñ²âÊÔ³ÌÐò£¬ÎÒ»¹ÊÇϲ»¶²ÉÓÃPHP¡£¼ò½à£¬·ç¸ñºÍC/C++½Ó½ü£¬ÉÏÊֿ죬¶øÇÒ¿âÒ²ºÜÆëÈ«¡£ÒÔǰΪ¹ã¶«Òƶ¯×öÒƶ¯ÐÐÒµÖն˵ÄÑÝʾ³ÌÐòʱ£¬²ÉÓùúÄÚÒ»¸öÐÖµÜдµÄFleaPHP¿ªÔ´¿ò¼Ü£¬Á½Öܲ»µ½µÄʱ¼ä£¬ÎÒ´ÓÒ»¸ö¶ÔPHPÒ»ÎÞËùÖªµÄˮƽ£¬¿ìËٵĸ㶨ÁË30¶à¸öÒ³ÃæµÄºǫ́£¬ºóÀ´ÑÝʾЧ¹ûÒ²²»´í£¬Ò²ºÜÎȶ¨£¬´Ó´Ë¶ÔPHPÓÐÁ ......
½ñÌì×öftpµÄ½çÃæ,×öµÄÏ൱ÓôÃÆ£¬ÅªµÃÐÄÇé¼°Æ䲻ˬ£¬ÔÚÍøÉÏËѵ½ËÀ¶¼²»ÖªµÀ¸ÃÔõô°ì£¬´òËãÃ÷ÌìÏÈ¿´¿´C£«£«
µÄÊÇÔõôŪµÄÔÙ˵¡£²»¹ý£¬ÏÖÔÚÎÒÏëдһϹØÓÚsocketµÄ±à³Ì¡£
ÏÈдһ¸öʱ¼ä·þÎñÆ÷°É£¬Ëû¼àÌý¶Ë¿Ú£¬²¢Çһ᷵»Ø ·þÎñÆ÷µÄʱ¼ä
server.py
#!/usr/bin/python
# Copyright (c) angelipin (angelipin@126.com)
import ......