Преглед изворни кода

fixed lesezeichenparser - ignoring table headers

Phil пре 5 година
родитељ
комит
65acb60129
1 измењених фајлова са 11 додато и 4 уклоњено
  1. 11 4
      main.py

+ 11 - 4
main.py

@@ -32,7 +32,7 @@ def Lesezeichen(sess):
     lpars = lesezeichenParser()
     content = response.content
     lpars.feed(str(content))
-    print(lparser.watchlist)
+    print(lpars.watchlist)
 
 def LesezeichenD():
     lpars = lesezeichenParser()
@@ -47,6 +47,7 @@ def LesezeichenD():
         #print(str(i) + ' - ' + watchlist[i]['name'] + ' - ' + str(watchlist[i]['new']))
 
 class lesezeichenParser(HTMLParser):
+    inHeader = False
     watchlist = []
     readlist = []
     inh4 = False
@@ -88,6 +89,9 @@ class lesezeichenParser(HTMLParser):
                 self.anime['new'] = True
             else:
                 self.anime['new'] = False
+            
+        if (self.inWatchlist or self.inReadlist) and tag == 'th':
+            inHeader = True
 
     def handle_endtag(self, tag):
         if tag == 'h4' and self.inh4:
@@ -98,9 +102,12 @@ class lesezeichenParser(HTMLParser):
             self.inWatchlist = False
         if tag == 'tr' and self.inRow:
             self.inRow = False
-            if self.inWatchlist:
-                print('adding ' + str(self.anime))
-                self.watchlist.append(self.anime)
+            if self.inHeader:
+                inHeader = Flase
+            else:
+                if self.inWatchlist:
+                    print('adding ' + str(self.anime))
+                    self.watchlist.append(self.anime)
         if tag == 'td' and self.inData:
             self.inData = False
         if self.inName and tag == 'a':