= 寫(xiě)成了== , 浪費(fèi)一下午

          Posted on 2008-08-09 16:21 left 閱讀(421) 評(píng)論(0)  編輯  收藏 所屬分類(lèi): python
           1 # for 金牌榜
           2 import HTMLParser
           3 
           4 class MyHTMLParser(HTMLParser.HTMLParser):
           5             
           6     def reset(self):
           7         print "reset"
           8         self._xp = ''
           9         self._xq = ''
          10         self._xs = False
          11         self.tds = []
          12         HTMLParser.HTMLParser.reset(self)
          13     
          14     def handle_starttag(self, tag, attrs):        
          15         if tag == 'td':
          16             if self._xp == 'tr':
          17                 self._xs = True
          18         else:
          19             pass
          20         
          21         self._xp = tag
          22         
          23             
          24     def handle_endtag(self, tag):
          25         
          26         if tag == 'tr':
          27             if self._xq == 'td':
          28                 self._xs = False
          29                 print " ".join(self.tds)
          30                 self.tds = []
          31         else:
          32             pass        
          33         self._xq = tag
          34         
          35             
          36     def handle_data(self, data):
          37         if self._xs:
          38             self.tds.append(data.strip())
          39         else:
          40             pass
          41             
          42 
          43 
          44 class MedalPage(webapp.RequestHandler):
          45     def get(self):        
          46         r = urlfetch.fetch('http://data2008.sports.tom.com/medaltop-1-1.shtml', method="GET")        
          47         if r.status_code == 200:
          48             content = r.content
          49             
          50             parser = MyHTMLParser()
          51             parser.feed(content)
          52             parser.close()      


          21 行寫(xiě)成了         self._xp == tag
          33 行寫(xiě)成了         self._xq = tag

          好久不弄python了 5555555555555555555555555555555555555555555555555
          浪費(fèi)以下午

           



          只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          posts - 14, comments - 9, trackbacks - 0, articles - 0

          Copyright © left

          主站蜘蛛池模板: 福安市| 扬中市| 东台市| 涞水县| 甘泉县| 新余市| 福贡县| 白沙| 西盟| 麦盖提县| 故城县| 来安县| 庄河市| 嘉定区| 马边| 正蓝旗| 托里县| 美姑县| 临江市| 司法| 大足县| 黑河市| 巴青县| 扎兰屯市| 和田市| 林甸县| 泾川县| 土默特左旗| 莆田市| 武宣县| 高阳县| 宁城县| 永嘉县| 广东省| 巴青县| 天祝| 扶风县| 绥德县| 阳江市| 延津县| 菏泽市|