4
« on: September 06, 2012, 10:24:00 am »
So i'm a bit confused about how to use a socket. I got how to make one/send data and all that, but how can I execute commands, such as send_keys in selenium? Could it be my lack of web programming knowledge thats inhibiting me? Any help would be greatly appreciated. Note: I think I might try and switch my project into C as well, but I can probably rework a python snippet too. Thanks.
Below are updated versions of my project (note to those who run this forum: If this is not appropriate to do, feel free to remove and shoot me a PM with some guidelines, but I thought a little on-going project updates would be nice). This has also turned into more of a twitter spammer, but, alas, I feel the principles could still be applicable. Also, I would like help on my question above as it would give my project MUCH MUCH more heft.
So, first and acct. creator:
from urllib import urlopen
import re
import string
import random
import time
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
lnum=['0', '1', '2', '3','4', '5', '6', '7', '8', '9']
llet=['a','b','c','d', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p','q','r','s','t','u','v','w', 'x', 'y' 'z']
names=[]
pw= ##pick a password you want to use.
for n in range(0,XXXXXX): ##pick how many accounts you want to create at in one ... spawn???
a=random.choice(llet)
b=random.choice(llet)
c=random.choice(lnum)
d=random.choice(lnum)
e=random.choice(lnum)
f=random.choice(llet)
g=random.choice(lnum)
h=random.choice(llet)
i=random.choice(llet)
j=random.choice(llet)
user = a+b+c+d+e+f+g+h+i+j+'@XXXX.com'
##generates random username with a low probability of being allready taken, also pick whatever mail service you want to hose it on.
names.append(user)
print user
browser= webdriver.Firefox()
browser.get('http://www.twitter.com')
elem = browser.find_element_by_name("user[name]")
elem.send_keys(a+b)
elem = browser.find_element_by_name("user[email]")
elem.send_keys(user)
elem= browser.find_element_by_name("user[user_password]")
elem.send_keys(pw)
browser.find_element_by_css_selector(".btn.signup-btn").click()
time.sleep(2)
browser.find_element_by_name("user[remember_me_on_signup]").click()
browser.find_element_by_css_selector(".submit.button.promotional").click()
##the above will launch X firefox window, and, sadly, you have to manually enter the captchas
f=open('tusers.txt', 'a')
for item in names:
f.write(item + '\n')
##finally writes them to a file for late use
Next is the actual spammer, you need to have a .txt file created with your possible tweets.
from urllib import urlopen
import re
import string
import random
import time
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from multiprocessing import Process, Array, Pool
users1=[]
amazon=[]
fly=[]
desc=[]
users2=[]
slogan=['WTF', 'THIS!', 'OMG', 'HAHA', 'YES', 'ITS MY BDAY', 'DRUNKK']
pw=XXXXX ##your password for the acts.
##below is the username file, followed by however many .txt files you need to make it work, i'm using three for my current project.
f = open('tusers.txt', 'r')
for line in f:
back = line.find('\n')
line = line[:back]
users1.append(line)
f.close()
f = open('alinks.txt', 'r')
for item in f:
if item !='\n':
amazon.append(item)
f.close()
f = open('flylinks.txt', 'r')
for item in f:
if item !='\n':
fly.append(item)
f.close()
f = open('descs.txt', 'r')
for item in f:
if item !='\n':
desc.append(item)
##checks xpath is vis.
def check_xpath(xpath,browser):
try:
browser.find_element_by_xpath(xpath)
except NoSuchElementException:
return False
return True
def twitter(user):
browser = webdriver.Firefox()
browser.get('http://www.twitter.com')
elem = browser.find_element_by_css_selector(".text-input.email-input")
elem.send_keys(str(user))
elem= browser.find_element_by_css_selector(".text-input.flex-table-input")
elem.send_keys(str(pw))
browser.find_element_by_css_selector(".submit.btn.primary-btn.flex-table-btn.js-submit").click()
print user + ' LOGGED IN'
time.sleep(2)
##below checks suspension
if check_xpath(".//*[@id='account-suspended']/span[1]", browser) == True:
print user + ' ' + 'SUSPENDED'
browser.close()
##if not suspended, find a hashtag, which will be tweeted
else:
p1=".//*[@id='page-node-home'][1][5][2]/ul/li["
p2=str(random.choice(range(2,6)))
p3="]/a"
path = p1+p2+p3
print 'path found'
if check_xpath(path, browser) == False:
browser.close()
return
elem = browser.find_element_by_xpath(path)
hashtag=elem.text
## If hashtag non-ascii it will not be used.
for char in hashtag:
if ord(char)>128:
hashtag=''
while(True):
try:
elem = browser.find_element_by_class_name("twitter-anywhere-tweet-box-editor")
elem.click()
##below tweets hashtag + random crap, use what you will.
elem.send_keys(str(hashtag) +' ' + random.choice(slogan)+ ' ' + random.choice(fly))
break
except NoSuchElementException:
time.sleep(.1)
browser.find_element_by_css_selector(".tweet-button.btn.primary-btn").click()
##below searches twitter RSS for a target user you want to reply to.
term = whatever the fuck you want.
st = term
webpage = urlopen('http://search.twitter.com/search.rss?q=' + st).read()
front = webpage.find('<author>')
back = webpage.find('@',front)
person=webpage[front+8:back]
##throws out bad searches
if 'ersion' in person:
twit=' '
else:
twit = '@'+person
if len(twit) > 100:
twit = ''
elem = browser.find_element_by_class_name("twitter-anywhere-tweet-box-editor")
##below checks shiz in text file, and cuts tweet, feel free to make the cut whereever you need.
detwee = desc[q][:87].decode('utf-8')
detwee = detwee.encode('utf-8')
##checks ascii, I could clean this whole section up.
for char in detwee:
if ord(char)>128:
detwee = 'WHOOPS'
##tweets you whiz
elem.send_keys(str(twit) +' ' + detwee+ ' ' + fly[q])
browser.find_element_by_css_selector(".tweet-button.btn.primary-btn").click()
browser.close()
##does it for all accounts in tusers, and keeps on a doin.
counter = 0
while(True):
for item in users1:
twitter(item)
counter +=1
print 'SENT TWEETS: ', counter
Still tweaking stuff, and there is some dumb shit I should clean up. My major problem is lack of threading or multi-processing as it will not work with selenium, so I'd like to recode it using C sockets (if possible) for multiprocessing/threading reasons. Also my C is really rusty, so it'd be nice practice. Also I cut out a large section which involved targeting my @ reply shit which I rather liked, but none of you all would probably want to see.
STAFF EDIT
Twice in the same thread. No double posting, you know how to use the edit button, be sure to use it next time instead of double posting