Phil 5 年之前
当前提交
9bf4da361d
共有 2 个文件被更改,包括 131 次插入0 次删除
  1. 39 0
      auth.py
  2. 92 0
      main.py

+ 39 - 0
auth.py

@@ -0,0 +1,39 @@
+import requests
+from html.parser import HTMLParser
+from html.entities import name2codepoint
+
+def run(user,passw):
+    sess = requests.Session()
+    #obtain token
+    response = requests.get('https://proxer.me/')
+    data = response.content
+    tparse = tokenParser()
+    tparse.feed(str(data))
+    token = tparse.token
+    cookies = response.cookies
+
+    #make auth
+    response = sess.post('https://proxer.me/login?' + token + '=1',
+        data={'username':user,'password':passw,'remember':'1','submit':'login'},
+        cookies=cookies)
+    cookies = response.cookies
+    #print(response.status_code)
+    #print(response.content)
+    
+    return sess
+
+    #test request
+    #response = requests.get('https://proxer.me/ucp?s=reminder&utm_source=nav#top',cookies=cookies)
+    #print(response.content)
+
+class tokenParser(HTMLParser):
+    token = ''
+
+    def handle_starttag(self, tag, attrs):
+        if tag == 'input' and attrs[2][1] == 'proxerToken':
+            self.token = attrs[1][1]
+            print('Token: ',self.token)
+
+
+#response = requests.get('https://proxer.me/ucp?s=reminder&utm_source=nav#top',cookies=cookies)
+#print(response.content)

+ 92 - 0
main.py

@@ -0,0 +1,92 @@
+import auth as auth
+from getpass import getpass
+import requests
+from html.parser import HTMLParser
+from html.entities import name2codepoint
+
+def main():
+    while True:
+        print('PYrxoer Python wrapper for proxer.me')
+        print('1 - Login')
+        print('2 - Lesezeichen - Anime')
+
+        uin = input('$>: ')
+        if uin == '1':
+            user = input('username: ')
+            pw = getpass('password:' )
+            sess = auth.run(user,pw)
+
+        if uin == '2':
+            Lesezeichen(sess)
+
+def Lesezeichen(sess):
+    response = sess.get('https://proxer.me/ucp?s=reminder&utm_source=nav#top')
+    lpars = lesezeichenParser()
+    lpars.feed(str(response.content))
+
+
+watchlist = []
+readlist = []
+
+
+class lesezeichenParser(HTMLParser):
+    inh4 = False
+    inWatchlist = False
+    inReadlist = False
+    inRow = False
+    inData = False
+    tdCount = 0
+    inName = False
+
+    def handle_starttag(self, tag, attrs):
+        #headline to diff read/watchlist
+        if tag == 'h4':
+            self.inh4 = True
+        
+        #tablerow for parsing entry
+        if (self.inWatchlist or self.inReadlist) and tag == 'tr':
+            self.inRow = True
+            self.tdCount = 0
+
+        #table data for parsing info
+        if self.inRow and tag == 'td':
+            self.tdCount +=1
+            self.inData = True
+
+        if self.inData and tag == 'a' and self.tdCount == 2:
+            self.inName = True
+
+
+    def handle_endtag(self, tag):
+        if tag == 'h4' and self.inh4:
+            self.inh4 = False
+        if tag == 'table' and self.inReadlist:
+            self.inReadlist = False
+        if tag == 'table' and self.inWatchlist:
+            self.inWatchlist = False
+        if tag == 'tr' and self.inRow:
+            self.inRow = False
+        if tag == 'td' and self.inData:
+            self.inData = False
+        if self.inName and tag == 'a':
+            self.inName = False
+
+    def handle_data(self, data):
+        if self.inh4 == True and data == 'Watchlist (Anime)':
+            self.inWatchlist = True
+            print('Watchlist:')
+
+        if self.inh4 and data == 'Readlist (Manga)':
+           self.inReadlist = True
+           print('Readlist:')
+
+        if self.inName:
+            if self.inWatchlist:
+                print(' Anime: '+data)
+            if self.inReadlist:
+                print(' Manga: '+data)
+
+
+
+
+main()