вот. Родил. Мой первый скрипт в веб-программинге. Работает
#!/usr/bin/python
import cgi
import urllib
import urllib2
import re
import cookielib
import time
def loginContact(nickname, password):
cookie = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(c ookie))
urllib2.install_opener(opener)
headers = {'User-Agent' : 'Mozilla/4.0 (compatible; MSIE 5.01; Widows NT)'}
data = {"email":nickname, "pass"

assword}
sendData = urllib.urlencode(data)
req = urllib2.Request("http://vkontakte.ru/login.php", sendData, headers)
try:
vk = str(urllib2.urlopen(req).info())
except:
cookie = status = "ERROR"
return cookie, status
else:
if "remixsid=deleted" in str(vk):
status = "NO"
return cookie, status
else:
status = "YES"
return cookie, status
def openSearch():
searchURL = "http://vkontakte.ru/search.php?q=%EA%E8%E5%E2&act=quick"
req = urllib2.Request(searchURL)
response = str(urllib2.urlopen(req).read())
addEx = re.compile('(?<=addToFriend\()\w+')
ids = addEx.findall(response)
return ids
def addFriend(ids):
urlArray = []
for id in ids:
friendURL = "http://vkontakte.ru/friend.php?act=a_add_form&fid=" + id
urlArray.append(friendURL)
for urlNum in range(1, len(urlArray)):
searchURL = urlArray[urlNum]
req = urllib2.Request(searchURL)
response = str(urllib2.urlopen(req).read())
addEx = re.compile('(?<=\")\w+')
hits = addEx.findall(response[850:950])
for i in range(0, len(hits)):
if hits[i] == 'h' and hits[i + 1] == 'h':
value = hits[i + 2]
break
addEx = re.compile('(?<!<\/a>)\w+', re.UNICODE)
hits = addEx.findall(response[500:700])
for i in range(0, len(hits)):
if hits[i] == ids[urlNum]:
firstName = hits[i + 1]
lastName = hits[i + 2]
break
url = 'http://vkontakte.ru/friend.php?act=addFriend&fid=' + ids[urlNum] + '&h=' + value + '&first_name=' + firstName + '&last_name=' + lastName + '&sex=&message='
req = urllib2.Request(url)
urllib2.urlopen(req).read()
time.sleep(2.5)
return responce
def main():
print "Content-type: text/html\n"
inputValue = cgi.FieldStorage()
name = inputValue["name"].value
passw = inputValue["pass"].value
go = loginContact(name, passw)
if go[1] == 'YES':
addFriend(openSearch())
main()