Python 3.13.5 (tags/v3.13.5:6cb20a2, Jun 11 2025, 16:15:46) [MSC v.1943 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
... from bs4 import BeautifulSoup
... from lxml import html
... import re
... def extract_numbers(text):
...     pattern = r'(\d+)\s*/\s*(\d+)'
...     match = re.search(pattern, text)
...     if match:
...         return int(match.group(1)), int(match.group(2))
...     else:
...         return None, None
... login_url = 'http://8.136.99.126/login'
... username = '035966_L3'
... password = '***********'
... session = requests.Session()
... payload = {'uname': username, 'password': password, 'rememberme': True}
... response = session.post(login_url, data = payload)
... if response.ok == False:
...     print('Login failed!')
...     print('Press any key to continue...')
...     input()
...     sys.exit(1)
... url = 'http://8.136.99.126/p?page='
... page = 0
... count = 0
... submits = 0
... continous = True
... while continous:
...     continous = False
...     page = page + 1
...     content = session.get(url + str(page))
...     if content.status_code == 200:
...         soup = BeautifulSoup(content.text, 'html.parser')
...         text = soup.get_text()
...         lines = text.splitlines()
...         for line in lines:
...             num1, num2 = extract_numbers(line)
...             if num1 != None:
...                 continous = True
...                 count = count + 1
...                 submits = submits + num2
...     else:
...         print('Crawling Failed!')
...         print('Press any key to continue...')
...         input()
...         sys.exit(1)
... print('Crawled!')
... print('Problem Count:', count)
... print('Submission Count:', submits)
... print('Press any key to continue...')
...
Crawled!
Problem Count: 184
Submission Count: 2000
Press any key to continue...

0 条评论

目前还没有评论...