Last active
May 18, 2018 01:43
-
-
Save maltoze/8959ae12f7fd16cdc86f24251129e8b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| import time | |
| from urllib import request, parse | |
| from threading import Timer | |
| headers = { | |
| 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36', | |
| } | |
| login_url = 'http://club.tgfcer.com/logging.php?action=login&' | |
| visit_url = 'http://club.tgfcer.com/forum-25-1.html' | |
| def login(): | |
| post_data = { | |
| 'loginfield': 'username', | |
| 'username': '*****', | |
| 'password': '******', | |
| 'questionid': '0', | |
| 'formhash': '67fb9c9c', | |
| 'referer': 'index.php', | |
| 'loginsubmit': True, | |
| 'cookietime': 2592000, | |
| } | |
| post_data = parse.urlencode(post_data).encode('utf-8') | |
| cookie_processor = request.HTTPCookieProcessor() | |
| opener = request.build_opener(cookie_processor) | |
| req = request.Request(login_url, headers=headers, data=post_data) | |
| # page = request.urlopen(req) | |
| opener.open(req) | |
| return opener | |
| def visit(opener): | |
| try: | |
| req = request.Request(visit_url, headers=headers) | |
| page = opener.open(req) | |
| content = page.read().decode('gbk') | |
| except Exception as e: | |
| content = '' | |
| print('Exception>>>', e) | |
| pattern = re.compile(r'.*您的信息: (.*?) 激骚.*', re.DOTALL) | |
| match_obj = pattern.match(content) | |
| if match_obj: | |
| print(match_obj.groups()[0]) | |
| else: | |
| print(content) | |
| t = Timer(30, visit, (opener,)) | |
| t.start() | |
| if __name__ == '__main__': | |
| visit(login()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment