Автоматизируем отправку комментариев в ЖЖ | akvatopia.ru

Автоматизируем отправку комментариев в ЖЖ

Написал тут скрипт для автопостинга сообщений к постам в ЖЖ. Писал, чтобы потроллить одно сообщество и его модераторов. Но можно и ссылки на дорвеи отправлять, например, хотя со ссылкой комменты скорее всего попадут в подозрительные). Или завалить чей-нибудь /inbox/ ЖЖ-шный и/или почтовый ящик сообщениями. Или можно напарсить комментариев (за оппозицию/за путина/за марсиан) и отправлять их жж противников этого. Тоже неплохо.

Настройка простая, вводим адрес community в жж и логины с паролями от аккаунтов которые будут отправлять сообщения. Единственное, членство в коммьюнити должно быть открытое, без модерации. Ну или можно завести десяток ботов, подождать когда отмодерируют и уже потом запускать скрипт.

Капчу не пробивает, это кому надо сами дописывайте, работает только там где добавление комментариев открыто авторизированным ЖЖ пользователям.

Короче вот:

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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import sys
import time
import re
import urllib
import urllib2
import cookielib
import httplib


COOKIE_FILE_TMPL = ".cookies/%s/cookie.txt"
COOKIE_DIR_TMPL = ".cookies/"

DEBUG = 0
DEBUG_REPLY = 0


def main_login(cj, ljuser, ljpass):

    #
    # load main page
    #

    reqUrl = 'http://www.livejournal.com/'
    f = urllib2.urlopen(reqUrl)
    data = f.read()
    if (DEBUG):
        print "MAIN PAGE"
        #print data


    #
    # request N1 (POST QUERY)
    #

    refererUrl = reqUrl
    reqUrl = 'https://www.livejournal.com/login.bml?ret=1'
    reqData = urllib.urlencode({'mode': 'login',
                                'user': ljuser,
                                'password': ljpass}
                          )
    req = urllib2.Request(url=reqUrl, data=reqData)
    req.add_header('Referer', refererUrl)
    f = urllib2.urlopen(req)
    data = f.read()

    if (DEBUG):
        print "LIVEJOURNAL ANSWER\n"
        print data

    #f = open("_login.txt", "w")
    #f.write(data)
    #f.close()

    re_getbackurl = re.compile(r'livejournal.com/logout.bml\?user=')
    m = re.search(re_getbackurl, data)
    if (m):
        print "Login success: " + ljuser
    else:
        print "Login fail, check login and pass"
        return "fail"

    return "ok"


def main_reply_one(cj, ljuser, ljpass, posturl, replytext):

    #
    # Load post
    #

    print posturl

    reqUrl = posturl
    f = urllib2.urlopen(reqUrl)
    data = f.read()
    if (DEBUG):
        print "LOAD POST"
        print data


    f = open("_post.txt", "w")
    f.write(data)
    f.close()


    #
    # Parse lj_form_auth
    #

    lj_form_auth = ""
    re_form_auth = re.compile(r' name="lj_form_auth" value="([^"]+)" ')
    m = re.search(re_form_auth, data)
    if (m):
        lj_form_auth = m.group(1)
        if (DEBUG_REPLY):
            print "form auth: " + lj_form_auth
    else:
        print "livejournal lj_form_auth parsing error"
        return "fail"


    #
    # Parse chrp1
    #

    chrp1 = ""
    re_form_auth = re.compile(r' name="chrp1" value="([^"]+)" ')
    m = re.search(re_form_auth, data)
    if (m):
        chrp1 = m.group(1)
        if (DEBUG_REPLY):
            print "form chrp1: " + chrp1
    else:
        print "livejournal chrp1 parsing error"
        return "fail"


    #
    # Parse chal
    #

    chal = ""
    re_form_auth = re.compile(r' name="chal" value="([^"]+)" ')
    m = re.search(re_form_auth, data)
    if (m):
        chal = m.group(1)
        if (DEBUG_REPLY):
            print "form chal: " + chal
    else:
        print "livejournal chal parsing error"
        return "fail"

    #
    # Parse itemid
    #

    itemid = ""
    re_form_auth = re.compile(r' name="itemid" value="([^"]+)" ')
    m = re.search(re_form_auth, data)
    if (m):
        itemid = m.group(1)
        if (DEBUG_REPLY):
            print "form itemid: " + itemid
    else:
        print "livejournal itemid parsing error"
        return "fail"


    #
    # Parse journal
    #

    journal = ""
    re_form_auth = re.compile(r' name="journal" value="([^"]+)" ')
    m = re.search(re_form_auth, data)
    if (m):
        journal = m.group(1)
        if (DEBUG_REPLY):
            print "form journal: " + journal
    else:
        print "livejournal journal parsing error"
        return "fail"


    print "form data parsed"

    #
    # convert ljuser to lowercase and "-" to "_"
    #

    ljuser=ljuser.lower()
    ljuser=ljuser.replace("-", "_");

    #
    # request N2 (POST) replyto
    #

    refererUrl = reqUrl
    reqUrl = 'http://www.livejournal.com/talkpost_do.bml'
    reqData = urllib.urlencode({
                                    'journal': journal,
                                    'itemid': itemid,
                                    'response': "",
                                    'lj_form_auth': lj_form_auth,
                                    'chrp1': chrp1,
                                    'chal': chal,
                                    'cookieuser': ljuser,
                                    'replyto': "0",
                                    'parenttalkid': "0",
                                    'editid': "",
                                    'json': "1",
                                    'talkpost_do': "0",
                                    'subject': "",
                                    'stylemine': "0",
                                    'viewing_thread': "",
                                    'usertype': "cookieuser",
                                    'userpost': "",
                                    'password': "",
                                    'openid:url': "",
                                    'prop_picture_keyword': "",
                                    'body': replytext
                                })



    req = urllib2.Request(url=reqUrl, data=reqData)
    req.add_header('Referer', refererUrl)
    f = urllib2.urlopen(req)
    data = f.read()

    print "form data send"

    f = open("_replyresp.txt", "w")
    f.write(data)
    f.close()

    if (DEBUG):
        print "REPLY POST ANSWER\n"
        print data


    print "Comment post reply:"
    print data.strip()


    #
    # checking return data
    #

    re_find = re.compile(r'xdreceiver.html\?type=commentator')
    m = re.search(re_find, data)
    if (m):
        print "Now comment posted, success!"
    else:
        print "livejournal reply response error"
        return "fail"

    return "ok"


#
# Join community
#

def main_join_community(communityurl):

    #
    # Load community feed
    #

    reqUrl = communityurl
    f = urllib2.urlopen(reqUrl)
    data = f.read()

    f = open("_communityfeed.txt", "w")
    f.write(data)
    f.close()

    if (DEBUG):
        print "LOAD COMMUNITY FEED"
        print data

    #
    # Find if we are already in members
    #

    re_getuser = re.compile(r'<p>You are a member of ')
    m = re.search(re_getuser, data)
    if (m):
        print "Already in members"
        return "ok"


    #
    # Find community name
    #

    re_getuser = re.compile(r'"display_username":"([^"]+?)"')
    m = re.search(re_getuser, data)
    if (m):
        user = m.group(1)
        if (DEBUG):
            print "get user: " + user
    else:
        print "get user from community feed error, no community name found"
        exit(1)


    # user

    print "User/community found: " + user

    # time

    millis = int(round(time.time() * 1000))
    millis = str(millis)
    print "Local time in milliseconds: " + millis


    #
    # request N1 GET
    #

    queryData = "?user=" + user
    queryData+= "&userid=0&userpic_url="
    queryData+= "&mode=getinfo"
    queryData+= "&_=" + millis

    reqUrl = communityurl + user + '/__rpc_ctxpopup' + queryData
    print reqUrl

    req = urllib2.Request(url=reqUrl)
    req.add_header('Referer', communityurl)
    req.addheaders = [('X-Requested-With', 'XMLHttpRequest')]
    f = urllib2.urlopen(req)
    data = f.read()
    #print data


    f = open("_ctxpopup.txt", "w")
    f.write(data)
    f.close()

    print "popup ajax loaded"

    #
    # get join group auth token
    #
    re_getjointoken = re.compile(r'"join_authtoken":"([^"]+?)"')
    m = re.search(re_getjointoken, data)
    if (m):
        join_authtoken = m.group(1)
        if (DEBUG):
            print "get join_authtoken: " + join_authtoken
    else:
        print "get join_authtoken from ctx_popup error, no token found"
        exit(1)

    print "join_authtoken found:\n" + join_authtoken

    #
    # request N2 (POST QUERY)
    #

    reqUrl = communityurl + user + '/__rpc_changerelation'
    print reqUrl

    reqData = urllib.urlencode({'target': user,
                                'action': 'join',
                                'auth_token': join_authtoken}
                              )
    req = urllib2.Request(url=reqUrl, data=reqData)
    req.add_header('Referer', communityurl)
    req.addheaders = [('X-Requested-With', 'XMLHttpRequest')]
    f = urllib2.urlopen(req)
    data = f.read()


    f = open("_ctxjoin.txt", "w")
    f.write(data)
    f.close()

    if (DEBUG):
        print "JOIN COMMUNITY ANSWER\n"
        print data


    re_getbackurl = re.compile(r'"is_banned":0,"success":1,"is_member":1,"is_friend":0')
    m = re.search(re_getbackurl, data)
    if (m):
        print "Join success"
    else:
        print "Join fail, check:\n" + data
        return "fail"

    print data

    return "ok"



#
# Get first N community posts
#
def main_get_community_posts(communityurl, number_post):

    reqUrl = communityurl
    f = urllib2.urlopen(reqUrl)
    data = f.read()

    f = open("_communityfeed.txt", "w")
    f.write(data)
    f.close()

    if (DEBUG):
        print "LOAD COMMUNITY FEED"
        print data

    re_find = re.compile(r'<a href="(.+?)" class="subj-link"')
    plinks = re.findall(re_find, data, re.DOTALL|re.MULTILINE)

    n_post = number_post+1
    plinks = plinks[1:n_post]

    for l in plinks:
        print l

    totalposts = 0
    if (plinks):
        totalposts = len(plinks)
        print "total links finded: " + str(totalposts)
    else:
        print "community posts urls parsing error"
        return "fail"

    return plinks


#
# Main process code
#
def main_process(ljuser, ljpass, community, replytext, number_post):

    #
    # make ".cookies" dir
    #

    cookies_dir = os.path.join(os.getcwd(), COOKIE_DIR_TMPL)
    if (not(os.path.exists(cookies_dir))):
        os.mkdir(cookies_dir)

    #
    # prepare request cookies
    #

    COOKIE_FILE_PATH = COOKIE_FILE_TMPL % ljuser
    cookie_file = os.path.join(os.getcwd(), COOKIE_FILE_PATH)

    cj = cookielib.CookieJar()
    cj = cookielib.MozillaCookieJar()

    if (not(os.path.exists(cookie_file))):
        if (not(os.path.exists(os.path.dirname(cookie_file)))):
            os.mkdir(os.path.dirname(cookie_file))
        cj.save(cookie_file)

    cj.load(cookie_file)
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    opener.addheaders = [('User-agent', 'Mozilla/5.0')]
    urllib2.install_opener(opener)

    #
    # Login
    #

    ret = main_login(cj, ljuser, ljpass)
    if ret == "fail":
        print "Login failed"
        exit(1)
   

    #
    # Join community
    #

    print "Join community: " + community
    ret = main_join_community(community)
    if (ret == "fail"):
        return "fail"

    print "Sleeping 10 sec."
    time.sleep(10)
   

    #
    # Get community first N post urls
    #

    print "Attacking community: " + community + " " + str(number_post)
    posts = main_get_community_posts(community, number_post)

    if (DEBUG):
        print posts

    #
    # Mass reply
    #

    for posturl in posts:
        #print posturl + " " + replytext
        ret = main_reply_one(cj, ljuser, ljpass, posturl, replytext)
        if ret == "ok":
            print "Reply successful"
        else:
            print "Reply failed"

    #
    # Saving state for analyze
    #

    print "All done!"

    return


def main():
   
    community = "http://ru_politics.livejournal.com/"

    #
    number_post=25

    ljuser="LJUSER LOGIN1"
    ljpass="LJUSER PASS1"
    replytext = '<font color="red" size="42">Путин - хуй!</font>'
    main_process(ljuser, ljpass, community, replytext, number_post)

    ljuser="LJUSER LOGIN2"
    ljpass="LJUSER PASS2"
    replytext = '<font color="red" size="42">Путин - хуй!</font>'
    main_process(ljuser, ljpass, community, replytext, number_post)

    ljuser="LJUSER LOGIN3"
    ljpass="LJUSER PASS3"
    replytext = '<font color="red" size="42">Путин - хуй!</font>'
    main_process(ljuser, ljpass, community, replytext, number_post)
    #


    return


if __name__ == "__main__":
    main()

А вот скрипт для атаки на отдельных ЖЖ пользователей, а не сообществ. Пусть будет отдельным файлом, лень совмещать и красиво делать.

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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
#!/usr/bin/python
# -*- coding: utf-8 -*-

import os
import sys
import time
import re
import urllib
import urllib2
import cookielib
import httplib


COOKIE_FILE_TMPL = ".cookies/%s/cookie.txt"
COOKIE_DIR_TMPL = ".cookies/"

DEBUG = 0
DEBUG_REPLY = 0


def main_login(cj, ljuser, ljpass):

    #
    # load main page
    #

    reqUrl = 'http://www.livejournal.com/'
    f = urllib2.urlopen(reqUrl)
    data = f.read()
    if (DEBUG):
        print "MAIN PAGE"
        #print data


    #
    # request N1 (POST QUERY)
    #

    refererUrl = reqUrl
    reqUrl = 'https://www.livejournal.com/login.bml?ret=1'
    reqData = urllib.urlencode({'mode': 'login',
                                'user': ljuser,
                                'password': ljpass}
                          )
    req = urllib2.Request(url=reqUrl, data=reqData)
    req.add_header('Referer', refererUrl)
    f = urllib2.urlopen(req)
    data = f.read()

    if (DEBUG):
        print "LIVEJOURNAL ANSWER\n"
        print data

    #f = open("_login.txt", "w")
    #f.write(data)
    #f.close()

    re_getbackurl = re.compile(r'livejournal.com/logout.bml\?user=')
    m = re.search(re_getbackurl, data)
    if (m):
        print "Login success: " + ljuser
    else:
        print "Login fail, check login and pass"
        return "fail"

    return "ok"


def main_reply_one(cj, ljuser, ljpass, posturl, replytext):

    #
    # Load post
    #

    print posturl

    reqUrl = posturl
    f = urllib2.urlopen(reqUrl)
    data = f.read()
    if (DEBUG):
        print "LOAD POST"
        print data


    f = open("_post.txt", "w")
    f.write(data)
    f.close()


    #
    # Parse lj_form_auth
    #

    lj_form_auth = ""
    re_form_auth = re.compile(r' name="lj_form_auth" value="([^"]+)" ')
    m = re.search(re_form_auth, data)
    if (m):
        lj_form_auth = m.group(1)
        if (DEBUG_REPLY):
            print "form auth: " + lj_form_auth
    else:
        print "livejournal lj_form_auth parsing error"
        return "fail"


    #
    # Parse chrp1
    #

    chrp1 = ""
    re_form_auth = re.compile(r' name="chrp1" value="([^"]+)" ')
    m = re.search(re_form_auth, data)
    if (m):
        chrp1 = m.group(1)
        if (DEBUG_REPLY):
            print "form chrp1: " + chrp1
    else:
        print "livejournal chrp1 parsing error"
        return "fail"


    #
    # Parse chal (try1)
    #

    chal = ""
    re_form_auth = re.compile(r' name="chal" value="([^"]+)" ')
    m = re.search(re_form_auth, data)
    if (m):
        chal = m.group(1)
        if (DEBUG_REPLY):
            print "form chal: " + chal
    else:
        print "livejournal chal try1 parsing error"
        #return "fail"


    #
    # Parse chal (try2)
    #

    if (chal == ""):

        re_form_auth = re.compile(r' name=\'chal\' id=\'login_chal\' value=\'([^"]+)\' ')
        m = re.search(re_form_auth, data)
        if (m):
            chal = m.group(1)
            if (DEBUG_REPLY):
                print "form chal: " + chal
        else:
            print "livejournal chal parsing error"
            return "fail"


    #
    # Parse itemid
    #

    itemid = ""
    re_form_auth = re.compile(r' name="itemid" value="([^"]+)" ')
    m = re.search(re_form_auth, data)
    if (m):
        itemid = m.group(1)
        if (DEBUG_REPLY):
            print "form itemid: " + itemid
    else:
        print "livejournal itemid parsing error"
        return "fail"


    #
    # Parse journal
    #

    journal = ""
    re_form_auth = re.compile(r' name="journal" value="([^"]+)" ')
    m = re.search(re_form_auth, data)
    if (m):
        journal = m.group(1)
        if (DEBUG_REPLY):
            print "form journal: " + journal
    else:
        print "livejournal journal parsing error"
        return "fail"


    print "form data parsed"

    #
    # convert ljuser to lowercase and "-" to "_"
    #

    ljuser=ljuser.lower()
    ljuser=ljuser.replace("-", "_");

    #
    # request N2 (POST) replyto
    #

    refererUrl = reqUrl
    reqUrl = 'http://www.livejournal.com/talkpost_do.bml'
    reqData = urllib.urlencode({
                                    'journal': journal,
                                    'itemid': itemid,
                                    'response': "",
                                    'lj_form_auth': lj_form_auth,
                                    'chrp1': chrp1,
                                    'chal': chal,
                                    'cookieuser': ljuser,
                                    'replyto': "0",
                                    'parenttalkid': "0",
                                    'editid': "",
                                    'json': "1",
                                    'talkpost_do': "0",
                                    'subject': "",
                                    'stylemine': "0",
                                    'viewing_thread': "",
                                    'usertype': "cookieuser",
                                    'userpost': "",
                                    'password': "",
                                    'openid:url': "",
                                    'prop_picture_keyword': "",
                                    'body': replytext
                                })



    req = urllib2.Request(url=reqUrl, data=reqData)
    req.add_header('Referer', refererUrl)
    f = urllib2.urlopen(req)
    data = f.read()

    print "form data send"

    f = open("_replyresp.txt", "w")
    f.write(data)
    f.close()

    if (DEBUG):
        print "REPLY POST ANSWER\n"
        print data


    print "Comment post reply:"
    print data.strip()


    #
    # checking return data
    #

    re_find = re.compile(r'xdreceiver.html\?type=commentator')
    m = re.search(re_find, data)
    if (m):
        print "Now comment posted, success!"
    else:
        print "livejournal reply response error"
        return "fail"

    return "ok"


#
# Add friend
#

def main_add_friend(communityurl):

    #
    # Load users feed
    #

    reqUrl = communityurl
    f = urllib2.urlopen(reqUrl)
    data = f.read()

    f = open("_friendfeed.txt", "w")
    f.write(data)
    f.close()

    if (DEBUG):
        print "LOAD FRIEND FEED"
        print data

    #
    # Find if we are already in members
    #

    re_getuser = re.compile(r'<p>You list ')
    m = re.search(re_getuser, data)
    if (m):
        print "Already in members"
        return "ok"


    #
    # Find community name
    #

    re_getuser = re.compile(r'"display_username":"([^"]+?)"')
    m = re.search(re_getuser, data)
    if (m):
        user = m.group(1)
        if (DEBUG):
            print "get user: " + user
    else:
        print "get user from community feed error, no community name found"
        exit(1)


    # user

    print "User/community found: " + user

    # time

    millis = int(round(time.time() * 1000))
    millis = str(millis)
    print "Local time in milliseconds: " + millis


    #
    # request N1 GET
    #

    queryData = "?user=" + user
    queryData+= "&userid=0&userpic_url="
    queryData+= "&mode=getinfo"
    queryData+= "&_=" + millis

    reqUrl = communityurl + user + '/__rpc_ctxpopup' + queryData
    print reqUrl

    req = urllib2.Request(url=reqUrl)
    req.add_header('Referer', communityurl)
    req.addheaders = [('X-Requested-With', 'XMLHttpRequest')]
    f = urllib2.urlopen(req)
    data = f.read()
    #print data


    f = open("_ctxpopup.txt", "w")
    f.write(data)
    f.close()

    print "popup ajax loaded"

    #
    # get join group auth token
    #
    re_getfriendtoken = re.compile(r'"addFriend_authtoken":"([^"]+?)"')
    m = re.search(re_getfriendtoken, data)
    if (m):
        friend_authtoken = m.group(1)
        if (DEBUG):
            print "get friend_authtoken: " + friend_authtoken
    else:
        print "get friend_authtoken from ctx_popup error, no token found"
        exit(1)

    print "friend_authtoken found:\n" + friend_authtoken

    #
    # request N2 (POST QUERY)
    #

    reqUrl = communityurl + user + '/__rpc_changerelation'
    print reqUrl

    reqData = urllib.urlencode({'target': user,
                                'action': 'addFriend',
                                'auth_token': friend_authtoken}
                              )
    req = urllib2.Request(url=reqUrl, data=reqData)
    req.add_header('Referer', communityurl)
    req.addheaders = [('X-Requested-With', 'XMLHttpRequest')]
    f = urllib2.urlopen(req)
    data = f.read()


    f = open("_ctxjoin.txt", "w")
    f.write(data)
    f.close()

    if (DEBUG):
        print "JOIN COMMUNITY ANSWER\n"
        print data


    re_getbackurl = re.compile(r'"is_banned":0,"success":1,"is_member":(0|1),"is_friend":1')
    m = re.search(re_getbackurl, data)
    if (m):
        print "Join success"
    else:
        print "Join fail, check:\n" + data
        return "fail"

    print data

    return "ok"



#
# Get first N community posts
#
def main_get_community_posts(communityurl, number_post):

    reqUrl = communityurl
    f = urllib2.urlopen(reqUrl)
    data = f.read()

    f = open("_communityfeed.txt", "w")
    f.write(data)
    f.close()

    if (DEBUG):
        print "LOAD COMMUNITY FEED"
        print data

    re_find = re.compile(r'<a href="('+communityurl+'\d+?\.html\?mode=reply)')
    plinks = re.findall(re_find, data, re.DOTALL|re.MULTILINE)

    #n_post = number_post+1
    #plinks = plinks[1:n_post]

    n_post = number_post
    plinks = plinks[0:n_post]

    for l in plinks:
        print l

    totalposts = 0
    if (plinks):
        totalposts = len(plinks)
        print "total links finded: " + str(totalposts)
    else:
        print "community posts urls parsing error"
        return "fail"

    return plinks


#
# Main process code
#
def main_process(ljuser, ljpass, community, replytext, number_post):

    #
    # make ".cookies" dir
    #

    cookies_dir = os.path.join(os.getcwd(), COOKIE_DIR_TMPL)
    if (not(os.path.exists(cookies_dir))):
        os.mkdir(cookies_dir)

    #
    # prepare request cookies
    #

    COOKIE_FILE_PATH = COOKIE_FILE_TMPL % ljuser
    cookie_file = os.path.join(os.getcwd(), COOKIE_FILE_PATH)

    cj = cookielib.CookieJar()
    cj = cookielib.MozillaCookieJar()

    if (not(os.path.exists(cookie_file))):
        if (not(os.path.exists(os.path.dirname(cookie_file)))):
            os.mkdir(os.path.dirname(cookie_file))
        cj.save(cookie_file)

    cj.load(cookie_file)
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    opener.addheaders = [('User-agent', 'Mozilla/5.0')]
    urllib2.install_opener(opener)

    #
    # Login
    #

    ret = main_login(cj, ljuser, ljpass)
    if ret == "fail":
        print "Login failed"
        exit(1)
   

    #
    # Add friend
    #

    print "Add friend: " + community
    ret = main_add_friend(community)
    if (ret == "fail"):
        return "fail"

    print "Sleeping 10 sec."
    time.sleep(10)
   

    #
    # Get community first N post urls
    #

    print "Attacking community: " + community + " " + str(number_post)
    posts = main_get_community_posts(community, number_post)

    if (DEBUG):
        print posts

    #
    # Mass reply
    #

    for posturl in posts:
        #print posturl + " " + replytext
        ret = main_reply_one(cj, ljuser, ljpass, posturl, replytext)
        if ret == "ok":
            print "Reply successful"
        else:
            print "Reply failed"

    #
    # Saving state for analyze
    #

    print "All done!"

    return


def main():
   
    community = "http://tema.livejournal.com/"

    #
    number_post=25

    replytext = 'Ты - хуй!'

    #
    ljuser="USER1"
    ljpass="PASS1"
    main_process(ljuser, ljpass, community, replytext, number_post)

    ljuser="USER2"
    ljpass="PASS2"
    main_process(ljuser, ljpass, community, replytext, number_post)

    ljuser="USER3"
    ljpass="PASS3"
    main_process(ljuser, ljpass, community, replytext, number_post)

    ljuser="USER4"
    ljpass="PASS4"
    main_process(ljuser, ljpass, community, replytext, number_post)

    ljuser="USER5"
    ljpass="PASS5"
    main_process(ljuser, ljpass, community, replytext, number_post)


    return


if __name__ == "__main__":
    main()

Скачать их можно тут.

Есть еще скрипт для создания почты на яндексе, но он как-то нестабильно работает его пока выкладывать не буду. Можно также скрипт для авторегистрации аккаунта в жж написать, но это и так ручками быстро делается, поэтому пока не вижу особого смысла.

Кстати, а вот тут оказывается есть скрытая админка жж, где можно посмотреть всяких юзеров из СУП-а и прочих суперадминов:
http://www.livejournal.com/admin/priv/
http://www.livejournal.com/admin/priv/?priv=siteadmin

Так что вот, можно развлекаться и экспериментировать.

P.S. Сейчас изучаю открытый код платформы ЖЖ, он на перле. Там много всего интересного. Думаю над тем чтобы поднять свой ЖЖ сервер с блэкджеком и шлюхам.

Tweet
хорошоплохо (никто еще не проголосовал)
Loading...Loading...

Leave a Reply

Using Gravatars in the comments - get your own and be recognized!

XHTML: These are some of the tags you can use: <a href=""> <b> <blockquote> <code> <em> <i> <strike> <strong>