Created
June 19, 2012 20:36
-
-
Save Visgean/2956388 to your computer and use it in GitHub Desktop.
This scripts automatically votes at denik.cz
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
| #! /usr/bin/python3 | |
| # -*- coding: UTF-8 -*- | |
| # @author: Visgean Skeloru | |
| # email: <visgean@gmail.com> | |
| # jabber: <visgean@jabber.org> | |
| # github: http://github.com/Visgean | |
| from http import cookiejar | |
| import urllib | |
| import re | |
| basic_url = "http://kladensky.denik.cz/miminka/miminko201120120119.html" | |
| child_id = "" | |
| def parse_token(data): | |
| print(data) | |
| data = "\n".join([str(x) for x in data.splitlines() if "token" in str(x)]) | |
| pattern = '''\<input type\="hidden" name\="anketa\[anketaId\]" value="(?P<anketa_id>\d*)" \/\>\<input type\="hidden" name\="anketa\[token\]" id\="(?P<token_id>.*)" value\="(?P<token_value>[-\w]+)"''' | |
| result = re.search(pattern, str(data)) | |
| if result: | |
| return result.group("anketa_id"), result.group("token_value") | |
| else: | |
| return None, None | |
| def parse_page(): | |
| global token, anketa_id, jar, opener | |
| jar = cookiejar.FileCookieJar("cookies") | |
| opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(jar)) | |
| response = opener.open(basic_url) | |
| data = response.read() | |
| anketa_id, token = parse_token(data) | |
| if token == "0" or "None": | |
| print("Token not suitable", token) | |
| parse_page() | |
| else: | |
| print("Token:", token) | |
| def send_data(): | |
| post_data = { | |
| "anketa[anketaId]" : anketa_id, | |
| "anketa[hlasovat]" : "Hlasovat", | |
| "anketa[odpovedId]": child_id, | |
| "anketa[token]" : token, | |
| } | |
| new_data = urllib.parse.urlencode(post_data) | |
| opener.addheaders = [("Referer", basic_url)] | |
| response = opener.open(basic_url, new_data.encode('UTF-8')) | |
| the_page = response.read() | |
| if __name__ == "__main__": | |
| parse_page() | |
| send_data() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment