usr bin env python coding utf-8 импорт библиотек from twill commands i

 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# импорт библиотек
from twill.commands import go, showforms, formclear, fv, submit, code, show,find, get_browser
import re, time
import os.path
login = 'spamer123' # введите логин, с которого будем спамить
passw = '123qwe' # введите пароль
go('http://tut.by')
code("200")
# ======================================================================
try:
fv("1", "login", login)
fv("1", "password", passw)
submit()
print u"You logged in!"
except:
print u"Login error!"
# ======================================================================
a = 0
a = raw_input(u"Insert for parsing 1 or 2 for spam: ")
if a == '1':
index = 0
links = []
while index<=3:
go('http://blog.tut.by/rating/?page='+str(index))
htmlpars = show()
links = links + re.findall('<td><a href="(http://[^>]*)/">http', htmlpars)
index = index+1
for link in links:
invalidFile = open('file.txt', 'a+')
invalidFile.write(link+"\n")
invalidFile.close ()
elif a == '2':
f = open("file.txt")
for l in open("file.txt"):
links = []
go(l)
htmlpars = show()
links = links + re.findall('<a href="(http://[.a-zA-Z0-9-/]*#comments)', htmlpars)
if links ==[]:
go(l)
htmlpars = show()
links = links + re.findall('<a href="(http://[.a-zA-Z0-9-/]*#respond)', htmlpars)
# ======================
for r in links:
go(r)
code("200")
try:
fv("2", "url", u"http://itblogger.ru".encode('utf8'))
fv("2", "comment", u"Да забыл хотел сказать еще раз спасибо".encode('utf8'))
submit()
print u"Form submitted."
except:
print u"Form not found!"
for r in links:
go(r)
code("200")
try:
fv("2", "url", u"http://itblogger.ru".encode('utf8'))
fv("2", "comment", u"Да забыл хотел сказать еще раз спасибо".encode('utf8'))
submit()
print u"Form submitted."
except:
print u"Form not found!"
else:
print "Error."