forked from rim99/vote_against_37
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·81 lines (68 loc) · 2.16 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# -*- coding: utf-8 -*-
from __future__ import print_function
from faker import Factory
import requests
import json
fake = Factory.create(locale='zh_CN')
def headers():
return {
'X-Forwarded-For': fake.ipv4(),
'User-Agent': fake.user_agent()
}
def vote(timeout=3):
username = fake.user_name()
email = fake.email()
real_name = fake.name()
s = requests.session()
s.headers.update(headers())
register_data = {
"userName": username,
"email": email,
"password": "123456",
"password1": "123456",
"realName": real_name,
"province": u"北京市",
"job": u"IT|互联网|通信",
"mobile": "",
"address": "",
}
register_data = {
'_ZVING_METHOD': 'Register.doRegister',
'_ZVING_URL': '%2Fregister',
'_ZVING_DATA': json.dumps(register_data),
'_ZVING_DATA_FORMAT': 'json',
}
url = "http://zqyj.chinalaw.gov.cn/ajax/invoke"
r1 = s.post(url, data=register_data, timeout=timeout)
print(r1.status_code, r1.text)
vote_data = {
'_ZVING_METHOD': 'SupportOppose.voteOppose',
'_ZVING_URL': '%2FdraftDetail',
'_ZVING_DATA': '{"ID":"45115"}',
'_ZVING_DATA_FORMAT': 'json',
}
r2 = s.post(url, data=vote_data, cookies=r1.cookies, timeout=timeout)
print(r2.status_code, r2.text)
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--count", help="vote how many times", default=10, type=int)
parser.add_argument("--timeout", help="request timeout, in seconds", default=3.0, type=float)
parser.add_argument("--forever", help="vote forever", action='store_true')
args = parser.parse_args()
if args.forever:
while True:
try:
vote(timeout=args.timeout)
except KeyboardInterrupt:
break
except Exception as e:
print(e)
else:
for i in range(args.count):
try:
vote(timeout=args.timeout)
except KeyboardInterrupt:
break
except Exception as e:
print(e)