Пример #1
0
 def getInfo(self):
     self.company = 'Citi'
     self.bureaus = 'Equifax'
     try:
         browser = Browser(driver_name='firefox')
         browser.visit(self.url)
         browser.driver.set_window_size(self.window_size_x, self.window_size_y)
         time.sleep(5)
         browser.find_by_id(self.username_id).fill(self.username)
         time.sleep(5)
         browser.find_by_name(self.password_name).fill(self.password)
         time.sleep(5)
         browser.find_by_value(self.loginbutton_value).click()
         time.sleep(10)
         browser.find_by_id(self.fico_button).click()
         time.sleep(10)
         self.score = browser.find_by_id(self.score_id).text.encode('ascii','ignore')
         self.score = re.sub("[^0-9]", "", self.score)
         self.scoreDate =  browser.find_by_id(self.date_id).text.encode('ascii','ignore')
         browser.quit()
         print(self.company + " succeeds!")
     except:
         print(self.company + " failed!")
         pdb.set_trace()
         if browser:
             browser.quit()
Пример #2
0
class hrmis():
    username = '******'
    pwd = 'ESS3BUAT'
    mainUrl = "http://showcase.aishk.com:7701/HRMIS-UAT2/html/login.jsp"

    def __init__(self):
        self.driver_name = 'firefox'
        self.executable_path = 'E:/driver/geckodriver'
        self.driver = Browser(driver_name=self.driver_name,
                              executable_path=self.executable_path)
        self.driver.visit(self.mainUrl)

    def login(self):
        self.driver.fill('opCNA', self.username)
        self.driver.fill('pwd', self.pwd)
        self.driver.find_by_name('Submit').last.click()

    def selectRole(self, role):
        self.driver.find_by_text(role).last.click()

    def convertApp(self, url):
        '''
            leave '../leave/index.jsp'
        '''
        self.driver.find_link_by_href(url).last().click()
Пример #3
0
def main():
    #br = Browser('chrome', executable_path='./chromedriver')
    br = Browser('chrome', executable_path='./chromedriver', headless=True)
    #print('opened')
    br.visit(URL)
    #print('visted')
    sleep(1)
    br.fill('user', NAME)
    br.fill('password', PASSWORD)
    br.find_by_name('Login').first.click()
    sleep(3)
Пример #4
0
    def webscrabe(self,string,account,password,index):
        borwser = Browser("chrome")

        borwser.visit("https://aca.nuk.edu.tw/Aca/login.asp")
        borwser.find_by_name("Account").first.fill(account)
        borwser.find_by_name("Password").first.fill(password)
        borwser.find_by_name("B1").click()
        borwser.visit("https://aca.nuk.edu.tw/SN2/Basic/Student.asp")
        borwser.find_by_name("No").first.fill(string)
        borwser.find_by_name("B3").click()
        name = borwser.find_by_xpath("//tbody[1]/tr[2]/td[3]").text
        department = borwser.find_by_xpath("//tbody[1]/tr[2]/td[5]").text
        self.typename(index,name,department)
        borwser.quit
Пример #5
0
def login_booking(netidname, netidpwd):
    b = Browser()
    b.visit('http://gym.sysu.edu.cn/index.html')
    login = b.find_link_by_href("javascript:login();")  # 找到登录按钮
    login.click()

    # 输入账号密码和验证码
    b.fill('username', netidname)
    b.fill('password', netidpwd)
    validcode = raw_input(
        'Please here enter the verification code of login interface manually:')
    b.fill('captcha', validcode)
    b.find_by_name('submit').click()  # 点击登录按钮
    return b
Пример #6
0
def reg(name, code, pwd):
    b = Browser()
    b.visit(HOST_NAME + "/reg")

    # reg
    b.fill('name', name)
    b.fill('code', code)
    b.fill('pwd', pwd)
    b.fill('organization', u"海工大")
    b.fill('position', u"管理系")
    b.select('degree', u"2")
    b.fill('title', u"学生")
    b.fill('college', u"海工大")
    b.fill('major', u"学生")
    b.find_by_name('submit').first.click()
Пример #7
0
def login():
    global browser

    # insert your own path-to-driver here
    #executable_path = {'executable_path': 'C:/Users/Jun/Documents/gab/chromedriver.exe'}
    #browser = Browser('chrome', **executable_path)
    browser = Browser('firefox', headless=True)
    browser = getHTML("https://gab.ai/")
	

    # It's an account I have already created
    username = "******"
    password = "******"
    browser.find_by_name("username").fill(username)
    browser.find_by_name("password").fill(password)
    print(browser.find_by_text("Login")[1].click())
Пример #8
0
def qianpiao():
	global b
	b = Browser(driver_name="chrome")
	b.visit(login_url)
	login()
	b.visit(zhangxueyou_url)

	ul = b.find_by_name(u"2017[A CLASSIC TOUR学友.经典] 世界巡回演唱会—扬州站")
	print(len(ul))
	for i in range(index,len(ul)):
		ul[i].check()
		if ul[i]['class'] != 'on':
			sleep(0.5)
			b.find_by_xpath(u'//*[@id="JqueBoxer"]/div[1]/a').click()
		else:
			break
	if login_url in b.url:
	 	login()

	b.find_by_xpath(u'//*[@id="JreltList"]/ul/li[3]/dl/input').fill(ticket_num)

	b.find_by_xpath(u"/html/body/div[12]/div[2]/div[3]/div[5]/a").click()

	b.find_by_xpath(u"//*[@id='zidTabs']/li[2]").check()

	b.find_by_xpath(u'//*[@id="payNew-conts-show"]/div[2]/ul/li[2]/input').click()
	while pay_oreder not in b.url:
		b.find_by_id(u'saveOrder').click()
Пример #9
0
def enter_discussion(name, code, pwd):
    b = Browser()
    b.visit(HOST_NAME)

    # login in
    b.fill('name', name)
    b.fill('code', code)
    b.fill('pwd', pwd)
    b.find_by_name('submit').first.click()

    # choose
    b.choose('classroom_id', '2')
    b.choose('course_id', '2')
    b.find_by_name('submit').first.click()

    # enter discuss-detail
    b.visit(HOST_NAME + '/discuss-detail_25')
Пример #10
0
class TemMail():
    def __init__(self):
        self.driver_name = 'chrome'
        self.executable_path = '/usr/local/bin/chromedriver'

        self.driver = Browser(driver_name=self.driver_name,
                              executable_path=self.executable_path)
        self.driver.driver.set_window_size(800, 800)
        self.driver.visit('https://www.moakt.com')
        self.driver.find_by_name('random').click()
        while self.driver.url == 'https://www.moakt.com/zh/mail':
            return

    def getMailName(self):
        sleep(1)
        self.driver.execute_script('changeAddress();')
        sleep(1)
        mailname = self.driver.find_by_id('email-address').text
        return mailname

    def getEmail(self):

        while True:
            self.driver.find_by_text(u"刷新列表").click()
            temdata = self.driver.find_by_text(u"激活您的ProcessOn帐号")
            if len(temdata) == 0:
                sleep(2)
            else:
                em = self.driver.find_by_text(u"激活您的ProcessOn帐号").first
                url = em["href"] + '/content'
                self.getEmailDea(url)
                break

    def getEmailDea(self, emlurl):

        self.driver.visit(emlurl)
        temtext = self.driver.html
        url_verify = re.findall(
            r"https://www.processon.com/signup/verification/\w+", temtext)
        ss_mail = requests.Session()
        rsp_verify = ss_mail.get(url_verify[0])

        if rsp_verify.status_code == 200:
            self.driver.quit()
        else:
            print("failure:" + rsp_verify.status_code)
Пример #11
0
class DVTTVedicConverter(object):
    def __init__(self):
        # We presume that you've installed chrome driver as per https://splinter.readthedocs.io/en/latest/drivers/chrome.html .
        self.browser = Browser('chrome', headless=True)
        self.browser.visit('file://' + os.path.join(os.path.dirname(__file__), "data", 'DV-TTVedicNormal ==_ यूनिकोड परिवर्तित्र.html'))
        
    def convert(self, text):
        input_box = self.browser.find_by_id("legacy_text")
        convert_button = self.browser.find_by_name("converter")
        input_box.fill(text)
        convert_button.click()
        output_box = self.browser.find_by_id("unicode_text")
        return output_box.value
Пример #12
0
def initBrowsers():
    global browsers
    global browser_available
    for i in range(browser_limit):
        browser_available.append(True)
        browser_count.append(0)
    for i in range(browser_limit):
        try:
            crawler = Browser('firefox', headless=True)
            crawler.visit("http://gab.ai")
            crawler.driver.implicitly_wait(3)
        
            username = "******"
            password = "******"
            crawler.find_by_name("username").fill(username)
            crawler.find_by_name("password").fill(password)
            crawler.find_by_text("Login")[1].click()
            browsers.append(crawler)
            print("BROWSER " + str(i) + " SET UP")
            browser_available[i] = True
        except:
            print("PROBLEM LOGGING IN... ABORTING")
            sys.exit()
    print("A TOTAL OF " + str(len(browsers)) + " BROWSERS WERE PREPARED")
Пример #13
0
def main():
	browser = Browser()
	#browser = Browser('zope.testbrowser') #when you want it to run in the background
	browser.visit(url)
	browser.fill('u_id', username)
	browser.fill('u_pw', password)
	browser.find_by_name('submit')[0].click()
	browser.find_link_by_text('here')[0].click()
	if browser.find_by_name('tran[1]_agree'):
		browser.check('tran[1]_agree')
		browser.check('tran[1]_fj1')
		browser.find_by_name('tran[1]_sched')[0].click()
	browser.fill('tran[1]_CALLNUM', callnumber)
	browser.find_by_name('tran[1]_act')[1].click()
	if browser.is_text_present('%s is full' % callnumber):
		print '%s full :(' % callnumber
	else:
		browser.find_by_name('tran[1]_act')[0].click()
		print 'happy times! enrolled in %s' % callnumber
		subprocess.call('crontab -r', shell=True)
	browser.quit()

	print '__END__'
def main():
#    browser = Browser('chrome')
    browser = Browser()
    browser.visit(PE_LOGIN)
    
    browser.fill('username', USERNAME)
    browser.fill('password', PASSWORD)
    button = browser.find_by_name('login')
    button.click()

    browser.visit(PE_COUNTRIES)
       
    f = open("/tmp/stat.html", "w")
    print >>f, browser.html
    f.close()
    
    browser.quit()

    print '__END__'
Пример #15
0
def main():
    #    browser = Browser('chrome')
    browser = Browser()
    browser.visit(PE_LOGIN)

    browser.fill('username', USERNAME)
    browser.fill('password', PASSWORD)
    button = browser.find_by_name('login')
    button.click()

    browser.visit(PE_COUNTRIES)

    f = open("/tmp/stat.html", "w")
    print >> f, browser.html
    f.close()

    browser.quit()

    print '__END__'
Пример #16
0
class ContactTest(TestCase):
    def setUp(self):
        self.browser = Browser()
        self.browser.visit(URL)

    def tearDown(self):
        self.browser.quit()

    def test_acess_contact_page(self):
        self.browser.find_by_name("contact").click()
        self.browser.title | should | equal_to("RiceTeam - Contato")

    def test_contact_sucess(self):
        self.browser.find_by_name("contact").click()
        self.browser.fill_in("name", "Usuário de teste")
        self.browser.fill_in("email", "*****@*****.**")
        self.browser.fill_in("message", "Mensagem de teste")
        self.browser.find_by_name("submit").click()
        contact_successful = self.browser.find_by_name("contact_successful")
        contact_successful | should | equal_to("Contato enviado!")
Пример #17
0
def search_click():
    browser = Browser('firefox', profile='fraudbot')

    # Visit URL
    url = "http://www.google.com" 
    browser.visit(url) 
    browser.fill('q', "karmachamillionaire") 
    time.sleep(1)

    # Find and click the 'search' button 
    button = browser.find_by_name("btnG") 

    # Interact with elements 
    button.click() 
    time.sleep(2)

    if browser.is_text_present("did not match any documents"):
        print "nobody likes us =("
    else:
        print "we're popular =)"

    browser.quit()
    login_url = 'http://www.chegg.com/login'
    with open('user.txt', 'r') as userFile:
        username = userFile.readline().strip()
        password = userFile.readline().strip()
    isHeadless = True
    b = Browser('firefox', headless=isHeadless)
    b.driver.maximize_window()
    print('entering login page')
    b.driver.get(login_url)
    print('entered login page')
    print('sleep 3')
    sleep(3)
    b.fill("email", username)
    b.fill("password", password)
    print('data filled')
    b.find_by_name(u"login").click()
    print('log in!')
    print('sleep 3')
    sleep(3)
    print('start!')

    # test
    b.driver.get(
        'http://www.chegg.com/homework-help/Digital-Signal-Processing-4th-edition-chapter-2-problem-1P-solution-9780073380490'
    )
    wait(b.driver)
    print('page getted')
    #answerElement = b.driver.find_element_by_id('solution-player-sdk')
    #ol = answerElement.find_element_by_tag_name('ol')
    #chapters = ol.find_elements_by_tag_name('li')
    #chapters_ol = b.driver.find_elements_by_class_name('chapters')
Пример #19
0
from splinter.browser import Browser

if __name__ == '__main__':
    x = Browser(driver_name="chrome")
    url = "https://www.meituan.com"
    x.visit(url)
    x.find_by_text(u"登录").click()
    x.fill("email", "username")
    x.fill("password", "password")
    x.find_by_name("commit").click()
Пример #20
0
class AutoTicketsBot(object):
    def __init__(self, config):
        self.userConfig = config['Config']
        self.browserConfig = config['Browser']
        self.username = self.userConfig['username']
        self.password = self.userConfig['password']
        self.homeUrl = self.userConfig['homeUrl']
        self.ticketPage = self.userConfig['ticketPage']
        self.driver_name = 'chrome'
        self.executablePath = self.userConfig['executablePath']
        self.ticketCount = self.userConfig['ticketCount']

    def initBrowser(self):
        self.driver = Browser(driver_name=self.driver_name, executable_path=self.executablePath)
        self.driver.driver.set_window_size(self.browserConfig['width'], self.browserConfig['height'])

    def visitHomePage(self):
        self.driver.visit(self.homeUrl)
        if self.driver.is_element_present_by_text('English', wait_time=5) is True:
            self.driver.find_by_text('English').first.click()
        else:
            raise RuntimeError("Failed to switch language to English in home page...") 

    def signInHomePage(self):
        if self.driver.is_element_present_by_text('Sign In', wait_time=5) is True:
            self.driver.find_by_text('Sign In').first.click()
        else:
            raise RuntimeError("Failed to find SignIn button in home page...")

        if self.driver.is_element_present_by_id('user_login', wait_time=2) is True:
            self.driver.find_by_id('user_login').fill(self.username)
        else:
            raise RuntimeError("Failed to fill account in signIn page...")
        
        if self.driver.is_element_present_by_id('user_password', wait_time=2) is True:
            self.driver.find_by_id('user_password').fill(self.password)
        else:
            raise RuntimeError("Failed to fill password in signIn page...")
        
        if self.driver.is_element_present_by_name('commit', wait_time=2) is True:
            self.driver.find_by_name('commit').first.click()
        else:
            raise RuntimeError("Failed to find SignIn button in signIn page...")

    def signInChecker(self, wait_time=3):
        if self.driver.is_element_not_present_by_text(self.username, wait_time=wait_time) is True:
            raise RuntimeError("Failed to sign in to the website...")
        
    def enterTicketPage(self):
        self.driver.visit(self.ticketPage)
        while self.driver.is_element_not_present_by_css('button[class="btn-default plus"]', wait_time=5) is True:
            self.driver.visit(self.ticketPage)

    def selectTicket(self):
        for __ in range(self.ticketCount):
            self.driver.find_by_css('button[class="btn-default plus"]')[-2].click()

        if self.driver.is_element_present_by_id('person_agree_terms', wait_time=2) is True:
            self.driver.find_by_id('person_agree_terms').check()
        else:
            raise RuntimeError("Failed to find agree_term checkbox in ticket page...")
        
        #self.captchaSolver("T2")

        if self.driver.is_element_present_by_text('Next Step', wait_time=2) is True:
            self.driver.find_by_text('Next Step').first.click()
        else:
            raise RuntimeError("Failed to find Next_Step button in ticket page...")

    def captchaSolver(self, answer):
        if self.driver.is_element_present_by_name('captcha_answer', wait_time=2) is True:
            self.driver.find_by_name('captcha_answer').fill('answer')
        else:
            raise RuntimeError("Failed to find Captcha in ticket page...")

    def quit(self):
        self.driver.quit()
Пример #21
0
def MakeNetwork():
    global bot
    global nonbot
    #global seen
    global primary_count
    global browser
    
    # cheat a little... cut the bot checking wait...
    global metacursor
    global metacon
    config = {
        'user': "******",
        'password': '******',
        'host': 'localhost',
        'database': 'Meta',
        'raise_on_warnings': True,
        'charset': 'utf8mb4',
        'collation': 'utf8mb4_bin'
    }
    metacon = mysql.connector.connect(**config)
    metacursor = metacon.cursor(buffered=True)
    readBots = "Select name from bots"
    botusers = DBexecuter("select", readBots, None, metacursor, metacon)
    for b in botusers:
        botuser = b[0].decode("utf-8")
        #seen.add(botuser)
        MakeSeen(botuser)
        AddBot(botuser)
        #bot.add(botuser)
        print("Added to botlist from DB: {}".format(botuser))
    
    
    #readUsers = "Select User.username from User left join Follows on User.username = Follows.followee where Follows.Follower is null order by User.followers desc"
    readUsers = "Select username from User"
    #readUsers = "Select `User`.`username` From User Order By User.Followers DESC"
    #readUsers = "Select A.Followee, (`User`.`followers` - A.counts) as Dif from (select Followee, count(*) as counts from Follows Group by Follows.Followee) as A join User on User.username = A.Followee order by Dif DESC"
    users = DBexecuter("select", readUsers, None, cursor, cnx)
    q = queue.Queue()
    for u in users:
        user = u[0].decode("utf-8")
        #seen.add(user)
        MakeSeen(user)
        nonbot.add(user)
        q.put(user)
        print("Added to network from DB: {}".format(user))
    global testcounter
    
    while not q.empty():
        # ensure we haven't gone over browse limit
        primary_count += 1
        if primary_count >= BROWSE_LIMIT:
            try:
                    browser.quit()
                    
                    crawler = Browser('firefox', headless=True)
                    crawler.visit("http://gab.ai")
                    crawler.driver.implicitly_wait(3)
                    
                    username = "******"
                    password = "******"
                    crawler.find_by_name("username").fill(username)
                    crawler.find_by_name("password").fill(password)
                    crawler.find_by_text("Login")[1].click()
                    browser = crawler
                    primary_count = 0
                    print("PRIMARY BROWSER RESET")
            except:
                print("failed to reset primary browser")
        
        user = q.get() # known not to be bot
        testcounter += 1
        print("\nSCRAPING " + user)
        print("grabbing followings")
        followings = AddNeighbors(user, False) # NOTE: THIS FILTERS BOTS ON ITS OWN
        print("grabbing followers")
        followers = AddNeighbors(user, True)
        print("found {} following".format(len(followings)))
        print("found {} followers".format(len(followers)))


        for f_raw in (followings + followers):
            try:
                f = f_raw.text[1:]
                if not UserSeen(f): # if user not yet seen .. IF SLOW, WE CAN MAKE THIS IF NOT USERINDB
                    print("\nappending user {} to the queue...".format(f))
                    q.put(f)
                    MakeSeen(f)
                print("there are now {} members in the queue".format(len(q)))
            except:
                print("error adding user to queue")
                continue
Пример #22
0
	loginList = open(sys.argv[1])
else:
	loginList = open('login.txt')							#open the the text file
credentials = loginList.readlines()							#read all the credentials in the text file


if datetime.datetime.today().weekday() == 0:				#if today is Monday
	maxCount = 60

while i < len(credentials):									#for each login credential
	b = Browser('chrome')									#create a browser instance
	loginURL = 'https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=12&ct=1400194110&rver=6.0.5286.0&wp=MBI&wreply=http:%2F%2Fwww.bing.com%2FPassport.aspx%3Frequrl%3Dhttp%253a%252f%252fwww.bing.com%252f&lc=1033&id=264960'
	b.visit(loginURL)										#login URL


	b.find_by_name('login').fill(credentials[i])			#find form using name ID (username)
	b.find_by_name('passwd').fill(pwd)						#find form using name ID (password)
	b.find_by_name('SI').click()							#find button using name ID (sign in button)

	time.sleep(5)											#delay 5s before starting to search

	while count < maxCount:									#perform the searches
		stub1 = searchFrom1[random.randrange(0, len(searchFrom1))]
		stub2 = searchFrom2[random.randrange(0, len(searchFrom2))]
		url = "http://www.bing.com/search?=setmkt=en-US&q="
		url += '%s+%s' % (stub1, stub2)
		b.visit(url)
		time.sleep(1)
		count += 1

Пример #23
0
class Redmine(object):

    activities_codes = {'Funcionalidade': '36', 'Codificacao': '25'}
    type_codes = {'Funcionalidade': '2', 'Codificacao': '7', 'Refatoramento': '14'}
    participants_code = {'59':'Douglas Camata',
                        '65': 'Felipe Norato Lacerda',
                        '60': 'Fernando Carvalho',
                        '149': 'Fábio Ribeiro',
                        '68': 'Priscila Manhaes da Silva',
                        '32': 'Rogério Atem'}

    def __init__(self):
        self.username = raw_input('Digite seu usuário: ')
        self.password = encode(getpass('Digite sua senha: '))
        self.prepare()

    def prepare(self):
        try:
          self.browser = Browser('chrome')
        except:
          self.browser = Browser()
        self.login()

    def login(self):
        self.browser.visit('http://sgsetec.renapi.gov.br/login')
        self.browser.fill('username', self.username)
        self.browser.fill('password', decode(self.password))
        self.browser.find_by_name('login').click()

    def visit_project(self, project_id):
        self.browser.visit('http://sgsetec.renapi.gov.br/kanban?project_id=%s' % project_id)

    def create_issue(self, project_id, type_name, title, description, begin, end, participants,
                        monitors):

        self.browser.visit('http://sgsetec.renapi.gov.br/projects/%s/issues/new' % project_id)
        self.browser.select('Tipo', self.type_codes[type_name])
        self.browser.fill('issue[subject]', title)
        self.browser.fill('issue[description]', description)
        self.browser.fill('issue[start_date]', begin)
        self.browser.fill('issue[due_date]', end)
        for participant in participants:
            self.browser.select('Participantes', self.participants_code[participant])
        for monitor in monitors:
            self.browser.select('Monitores', self.participants_code[monitor])
        self.browser.find_by_value('Criar').click()

    def update_issue(self, issue_id, activity, date,
                                    worked_hours=4, comment=None):
        self.browser.visit('http://sgsetec.renapi.gov.br/issues/%s/time_entries/new' % issue_id)
        self.browser.fill('time_entry[spent_on]', date)
        self.browser.find_by_id('time_entry_hours').fill(worked_hours)
        self.browser.select('time_entry[activity_id]', self.activities_codes[activity.capitalize()])
        self.browser.find_by_value('Salvar').click()

    def finish_issue(self, issue_id, begin, total_days, activity):
        #do not need to plus um day into cause first day of work is 'begin'
        day_worked = 0
        while day_worked < total_days:
            date = datetime.datetime.strptime(begin, "%Y-%m-%d")
            date = date.date() + datetime.timedelta(day_worked)
            day_worked += 1
            if date.weekday() > 4:
              total_days += 1
              continue
              date = date.date() + datetime.timedelta(day_worked)
            self.update_issue(issue_id=issue_id, date=str(date), activity=activity)
        self.close_issue(issue_id)


    def close_issue(self, issue_id):
        self.browser.visit('http://sgsetec.renapi.gov.br/issues/%s/time_entries/new' % issue_id)
        self.browser.select('issue[status_id]', '3')
        self.browser.select('issue[done_ratio]', '100')
        self.browser.find_by_value('Salvar').click()
Пример #24
0
class Amazon(object):
    def __init__(self, keyword):
        self.url = "https://www.amazon.com"
        self.name = "".join(random.sample(string.ascii_letters + string.digits, 6))
        self.email = "".join(random.sample(string.ascii_letters + string.digits, 16)) + "@163.com"
        self.password = "".join(random.sample(string.ascii_letters + string.digits, 8))
        self.keyword = keyword
        self.chrome_options = Options()
        logging.basicConfig(filename='amazon.log', level=logging.DEBUG)
        self.conn = pymysql.connect(host='192.168.0.211', port=6033, user='******', password='******', db='amazon')
        self.cs = self.conn.cursor()
        self.cs.execute('select id,ip,port from register_proxy_ips where is_alived = 1 order by id desc limit 1')
        self.proxy_ip = self.cs.fetchone()
        self.cs.execute('update register_proxy_ips set is_alived = 0 where id = %s' % self.proxy_ip[0])
        self.conn.commit()
        logging.debug(self.proxy_ip)
        # self.chrome_options.add_argument('--proxy-server=http://{host}:{port}'.format(host=self.proxy_ip[1], port=self.proxy_ip[2]))
        self.browser = Browser('chrome', user_agent=generate_user_agent(device_type='desktop'))

    def run(self):
        self.acess()
        self.search_kw()
        i = 1
        while i < 7:
            ad_list = self.browser.find_by_xpath('//li[contains(@class, "AdHolder")]')
            if ad_list:
                ad_list[0].find_by_tag('h2').click()
                break
            else:
                time.sleep(300)
                self.search_kw()
                i += 1
        if i > 6:
            self.browser.quit()
        self.register()
        self.add_pay_method()
        self.add_address()
        self.buy_goods()
        self.add_list()

    def acess(self):
        self.browser.visit(self.url)
        logging.error("代理IP失效,请求不成功")

    def search_kw(self):
        self.browser.find_by_xpath('//input[@id="twotabsearchtextbox"]').first.fill(self.keyword)
        self.browser.find_by_xpath('//input[@value="Go"]').click()
        draggble = self.browser.find_by_xpath('//*[@id="searchTemplate"]')
        target = self.browser.find_by_xpath('//*[@id="footer"]')
        draggble.drag_and_drop(target)
        # time.sleep(random.randint(1, 6))

    def register(self):
        self.browser.find_by_xpath('//*[@id="nav-link-accountList"]').click()
        self.browser.find_by_xpath('//*[@id="createAccountSubmit"]').click()
        self.browser.find_by_xpath('//input[@id="ap_customer_name"]').first.fill(self.name)
        self.browser.find_by_xpath('//input[@id="ap_email"]').first.fill(self.email)
        self.browser.find_by_xpath('//input[@id="ap_password"]').first.fill(self.password)
        self.browser.find_by_xpath('//input[@id="ap_password_check"]').first.fill(self.password)
        self.browser.find_by_xpath('//input[@class="a-button-input"]').click()

    def add_pay_method(self):
        self.browser.find_by_xpath('//*[@id="nav-link-accountList"]').click()
        self.browser.find_by_xpath('//*[@id="a-page"]/div[3]/div/div[2]/div[2]/a/div').click()
        self.browser.fill('ppw-accountHolderName', paras['card_name'])
        self.browser.fill('addCreditCardNumber', paras['card_num'])
        self.browser.execute_script('document.getElementsByName("ppw-expirationDate_month")[0].style.display="block"')
        self.browser.execute_script('document.getElementsByName("ppw-expirationDate_year")[0].style.display="block"')
        self.browser.find_by_text('04').click()
        self.browser.find_by_text('2019').click()
        self.browser.find_by_name('ppw-widgetEvent:AddCreditCardEvent').click()

    def add_address(self):
        self.browser.fill('ppw-fullName', paras['fullname'])
        self.browser.fill('ppw-line1', paras['line'])
        self.browser.fill('ppw-city', paras['city'])
        self.browser.fill('ppw-stateOrRegion', paras['stateOrRegion'])
        self.browser.fill('ppw-postalCode', paras['postalCode'])
        self.browser.fill('ppw-phoneNumber', paras['phoneNumber'])
        self.browser.find_by_name('ppw-widgetEvent:AddAddressEvent').click()

    def buy_goods(self):
        self.browser.find_by_xpath('//*[@id="nav-recently-viewed"]').click()
        self.browser.find_by_xpath('//*[@id="asin_list"]/div[1]/div/a/div[1]/span/div').click()
        try:
            self.browser.find_by_xpath('//*[@id="add-to-cart-button"]').click()  # add cart
            self.browser.find_by_xpath('//*[@id="smartShelfAddToCartNative"]').click()
        except Exception as e:
            logging.error(e)
        try:
            time.sleep(5)
            self.browser.is_element_present_by_xpath('//i[@class="a-icon a-icon-close"]', wait_time=30)
            self.browser.find_by_xpath('//i[@class="a-icon a-icon-close"]').click()
        except Exception:
            pass
        try:
            self.browser.find_by_xpath('//a[@id="hlb-view-cart-announce"]').click()  # enter cart
        except Exception:
            pass
        self.browser.execute_script('document.getElementsByName("quantity")[0].style.display="block"')
        self.browser.find_by_value('10').click()
        self.browser.find_by_name('quantityBox').clear()
        self.browser.fill('quantityBox', 999)
        self.browser.find_by_xpath('//span[@id="a-autoid-1"]').click()
        self.browser.find_by_xpath('//div[@class="sc-proceed-to-checkout"]').click()
        self.browser.find_by_xpath('//*[@id="address-book-entry-0"]/div[2]/span/a').click()
        self.browser.find_by_xpath('//*[@id="shippingOptionFormId"]/div[3]/div/div/span[1]').click()
        self.browser.find_by_xpath('//*[@id="order-summary-container"]/div/div/div').click()
        try:
            self.browser.find_by_xpath('//a[contains(@class, "prime-nothanks-button")]').click()
        except Exception:
            pass
        self.browser.find_by_xpath('//span[contains(@class, "place-order-button-link")]').click()

    def add_list(self):
        self.browser.find_by_xpath('//*[@id="nav-recently-viewed"]').click()
        self.browser.find_by_xpath('//*[@id="asin_list"]/div[1]/div/a/div[1]/span/div').click()
        self.browser.find_by_xpath('//input[@title="Add to List"]').click()
        if self.browser.is_element_present_by_text('Add to your list', wait_time=10):
            self.browser.find_by_xpath('//*[@id="WLHUC_result"]/form/div[2]/span[3]/span').click()
            self.browser.find_by_xpath('//i[@class="a-icon a-icon-close"]').click()
        time.sleep(2)
        self.browser.quit()
Пример #25
0
class Redmine(object):

    def __init__(self, url, login, password, project,
                                                   custom_project_params=None):
        """ This will open redmine page, and then login

            url: your redmine url
            login: your redmine login
            password: your redmine password
            project: the id of your project
            custom_project_params: some custom parameters to pass into projects
                url, in order to create a new issue
        """
        if not url.endswith('/'):
            url += '/'
        self._url = url
        self._login = login
        self._password = password
        self._project = project
        self._custom_project_params = custom_project_params

        self._browser = Browser()
        self._do_login()

    def _do_login(self):
        self._browser.visit(self._url + LOGIN_URL)
        self._browser.fill('username', self._login)
        self._browser.fill('password', self._password)
        self._browser.find_by_name('login').first.click()

    def create_issue(self, stop_before_commit=False, **issue_fields):
        """ Create a new issue into your redmine.

        This is an awesome (crazy) method. Pay attention:

        - You need to pass at least the required fields of your redmine.
          * For instance, if my redmine requires a title, and this field has the
          name:
                'issue[subject]'

          than I must pass my title as follows:
               create_issue(subject='My name')

        - You can also pass the name of other fields you'd like to fill,
          remembering to just pass the inner content of the field's name.
          For example, in this case:
                'issue[another_field]'
          The parameter would be:
              create_issue(another_field='My content')

        - As an example, in a default Redmine, I think this are the default
          required parameters that you must pass:
              create_issue(tracker_id, subject, description, assigned_to_id,
                           start_date, due_date, estimated_hours)

        - stop_before_commit is a flag, used when you have some extra fields that
          are not yet handled by this method, so you need to deal with it by
          hand. In this cases, call this method like this:
              create_issue(do_not_commit=True)

          And the method will just fill the fields you passed, without clicking
          'commit' button.

        - IMPORTANT: Scenarios that contains custom fields are also covered.
          A custom field has its name as something like:
              'issue[custom_field_values][20]'

          In this cases, you must pass a 'custom_field_values' parameter as a dict,
          where the key is the number of the field, and the value is the content
          you want. In this example, the parameter would be as follows:
              create_issue(custom_field_values={'20': 'My content'})

          Then the method will do the rest.
        """
        new_issue_url = self._url + PROJECT_TAG + '/' + self._project + '/issues/new'
        if self._custom_project_params:
            new_issue_url += '?%s' % self._custom_project_params
        self._browser.visit(new_issue_url)

        def fill_custom_field(field_id, field_value):
            for custom_field_number, custom_field_value in field_value.items():
                self._browser.fill(ISSUE_TAG + '[%s][%s]' % (field_id,
                    custom_field_number), custom_field_value)
        for field_id, field_value in issue_fields.items():
            if type(field_value) == type({}):
                fill_custom_field(field_id, field_value)
            else:
                self._browser.fill(ISSUE_TAG + '[%s]' % field_id, field_value)

        if not stop_before_commit:
            self._browser.find_by_name('commit').first.click()
        # TODO: find 'task_id' to return
        # (the last number under page url may be this)

    def fill_time(self, issue_id, start_date, end_date, time_per_day):
        """ Fill time into some issue that already exists.

            issue_id: id of the existing issue
            start_date: date to start filling in time
            end_date: date to end filling in time (self-including)

        - Pass start and end date as YYYY-MM-DD format, like on this example:

            fill_time(1, start_date="2011-04-23", end_date="2011-04-27", 4)

          Following this example, after method is run, the issue with id '1'
          will have, from monday to friday (2011/04/23, 2011/04/27), a new
          working time, with value 4 (4 hours), with a total of 20 hours worked
          on the week.
        """
        def discover_working_days(start_date, end_date, time_per_day):
            # format date
            start_date = strptime(start_date, '%Y-%m-%d')
            end_date = strptime(end_date, '%Y-%m-%d')
            # convert date to datetime
            start_date = datetime.date(start_date.tm_year, start_date.tm_mon,
                                                             start_date.tm_mday)
            end_date = datetime.date(end_date.tm_year, end_date.tm_mon,
                                                               end_date.tm_mday)

            working_days = []
            total_number_of_days = (end_date - start_date).days + 1

            current_date = start_date
            for day in range(total_number_of_days):
                if current_date.isoweekday() in range(1, 6): # working day [1,2,3,4,5]
                    date = current_date.strftime('%Y-%m-%d')
                    working_days.append((date, time_per_day))
                current_date = datetime.timedelta(days=1) + current_date

            return working_days

        working_days = discover_working_days(start_date, end_date, time_per_day)
        # like: [("2011-03-14", 4), ("2011-03-15", 4), .....]

        new_time_url = self._url + ISSUE_TAG + 's/' + issue_id + '/' + TIME_URL
        for date, hour in working_days:
            self._browser.visit(new_time_url)
            self._browser.fill(TIME_TAG + '[spent_on]', str(date)) # "2011-03-14"
            self._browser.fill(TIME_TAG + '[hours]', str(hour))
            self._browser.find_by_name('commit').first.click()

    def close_issue(self, issue_id):
        issue_url = ISSUE_TAG + 's/' + issue_id
        self._browser.open(self._url + issue_url)
        self._browser.find_link_by_partial_href(issue_url + '/edit').first.click()
        self._browser.select(ISSUE_TAG + '[done_ratio]', "label=100 %")
        self._browser.select(ISSUE_TAG + '[status_id]', "label=Resolvido")
        self._browser.find_by_name('commit').first.click()
Пример #26
0
#!usr/bin/python
from splinter.browser import Browser
import re
import time

br=Browser()
br.visit("http://www.160by2.com/Index")
br.fill('username','YOUR_PHONE_NUMBER_USED_TO_CREATE_160BY2_ACCOUNT')
br.fill('password','YOUR_ACCOUNT_PASSWORD')
button = br.find_by_name("")
button.click()

stringurl=br.url
stringurl2=stringurl.split("id=",1)[1]
id=stringurl2.split("id=",1)[1]
jsstring="window.parent.openPage('SendSMS?id="+id+"', 'aSendSMS', 'aSMS', 'ulSMS')"
br.execute_script(jsstring)
time.sleep(8)
br.execute_script(jsstring)
print "JS Executed"
time.sleep(8)

with br.get_iframe('by2Frame') as iframe:
	iframe.fill("sendSMSMsg","Well, I guess robot's do send SMSes when spandan wants them to ;)")
	iframe.find_by_tag("input")[10].fill("THE_PHONE_NUMBER_YOU_WANT_TO_SEND_SMS_TO")
	button2=iframe.find_by_id("btnsendsms").first
	print button2.value
	button2.click()
Пример #27
0
from splinter.browser import Browser
from selenium import webdriver

browser = Browser('chrome')
browser.visit('http://localhost:8000')
browser.fill('query', 'apple')
browser.find_by_name('submit').click()

if browser.is_text_present('Apple'):
    print("It found the food!")
else:
    print("Uh oh, no food found")

browser.quit()
Пример #28
0
# fp.close()

browser = Browser('chrome')
browser.visit('http://electsys.sjtu.edu.cn/edu/index.aspx')
browser.find_link_by_href('login.aspx').click()
print(browser.cookies.all())
cookie = '; '.join([('%s=%s' % x)
                    for x in list(browser.cookies.all().items())])
print(cookie)

req = urllib.request.Request(captcha_url, headers={'cookie': cookie})
res = urllib.request.urlopen(req)
content = res.read()
fp = open('captcha.jpg', 'wb')
fp.write(content)
fp.close()

image = Image.open('captcha.jpg')
image.load()
vcode = pytesseract.image_to_string(image)
print(vcode)

browser.fill('user', 'hnxxjyt')
browser.fill('pass', 'Sam229')
browser.fill('captcha', vcode)
browser.find_by_name('imageField').click()

# opener = urllib2.build_opener()
# opener.addheaders.append(('Cookie', 'cookiename=cookievalue'))
# f = opener.open("http://example.com/")
class game_iface():

    def __init__(self, game_address='http://www.gamesforthebrain.com/game/checkers/'):
        ''' Each instance of the application has its own browser. '''
        self.browser = Browser()
        self.browser.visit(game_address)

    def get_state(self):
        '''
            Get the state of the board we are playing on.
            @return: a dictionary.
                Each key is a square on the board.
        '''
        board_html = self.browser.find_by_.id('board').html.replace('\n', '')
        board = [x.split('"')[1:4] for x in str(board_html).split("><")]
        '''
            Explanation of HTML:
            owner, space name
            Black cannot be used
            Gray empty
            Me1 Computer
            Me King
            You1 Player
            You king
            y[0]: owner
            y[2]: board position
        '''
        return self.to_dict([(y[0], y[2]) for y in board if len(y) == 3])

    def to_dict(self, game):
        ''' Return a dictionary representation of the game. '''
        return {x[1]: x[0] for x in game}

    def move_piece(self, start_pos, end_pos):
        '''
            Move a piece from one position to another.

            @start_pos: string
                name of the position of the piece to be moved

            @end_pos: string
                name of the position where the move ends

            @return: boolean
                If the move succeeded or failed
        '''
        try:
            element = self.browser.find_by_name(start_pos)
            element.click()

            element = self.browser.find_by_name(end_pos)
            element.click()

        except AttributeError:
            # One of the elements doesn't exist and the move failed.
            return False

        # Move succeeded.
        return True

    def double_jump(self, start_pos, interim_pos, end_pos):
        '''
            Jumping over two pieces.
            
            @start_pos: string
                name of the position of the piece to be moved

            @interim_pos: string
                name of the position that finishes the first jump

            @end_pos: string
                name of the position where the move ends

            @return: boolean
                If the move succeeded or failed
        '''
        try:
            self.move_piece(start_pos, interim_pos)
            time.sleep(SLEEPTIME)
            element = self.browser.find_by_name(end_pos)
            element.click()
        except AttributeError:
            # One of the elements doesn't exist and the move failed.
            return False

        # Move succeeded.
        return True
Пример #30
0
from splinter.browser import Browser

url = raw_input('url:')


browser = Browser('firefox')
browser.visit(url)


if "nike" in url:
    button = browser.find_by_name("add-to-cart-button")
    sizeButton = browser.find_by_name("skuAndSize")
elif "adidas" in url:
    button = browser.find_by_id("buyingtools-add-to-cart-button")

sizeButton.click();

button.click()
Пример #31
0
def huoche():
    ends = "%u5357%u660C%2CNCG"
    global b
    b = Browser(driver_name="chrome")
    # b = Browser()
    b.visit(ticket_url)
    # b.execute_script('alert("开始刷票喽~~~~")')
    # sleep(2)
    # b.get_alert().dismiss()
    
    while b.is_text_present(u"登录"):
        sleep(1)
        login()
        if b.url == initmy_url:
            break
      
    try:
        #跳回购票页面
        b.visit(ticket_url)
        
        #加载查询信息
        b.cookies.add({"_jc_save_fromStation":starts})
        b.cookies.add({"_jc_save_toStation":ends})
        b.cookies.add({"_jc_save_fromDate":starttime})
        b.cookies.add({"_jc_save_toDate":endtime})
        b.reload()
        i = 1        
        
        b.find_by_name(ttype)[4].click()
        stations = b.find_by_name(fromStation)
        if stations:
            stations[0].click()
        else:
            print "no stations can select"    

        #循环点击预订
        if order != 0:
            while b.url == ticket_url:
                print "execute loop order != 0"
                b.find_by_text(u"查询").click()
                
                if b.find_by_text(u"预订"):
                    sleep(0.3)
                    b.find_by_text(u"预订")[order - 1].click()
                    print b.url
                    
                    if b.is_text_present(u"证件号码",wait_time=0.2):
#                        print [ i.text for i in b.find_by_text(pa) ]
                        b.find_by_id("normalPassenger_0").click()
                        b.find_by_id("normalPassenger_1").click()
                        
                else:
                    # b.execute_script('alert("似乎没有可预订选项")')
                    # b.get_alert().dismiss()
                    print "似乎没有可预订选项"
                    pass
                 
        else:
            while b.url == ticket_url:
                print "execute loop order == 0"
                b.find_by_text(u"查询").click()
                if b.find_by_text(u"预订"):
                    sleep(0.3)
                    for i in b.find_by_text(u"预订"):                 
                        i.click()
                        sleep(0.1)
                        if b.is_text_present(u"证件号码"):
                            # b.find_by_text(pa)[1].click()
                            b.find_by_id("normalPassenger_0").click()
                            b.find_by_id("normalPassenger_1").click()
                            # b.find_by_text("李芷嫣")[0].click()
                                                        
                    else:
                        # b.execute_script('alert("似乎没有可预订选项")')
                        # b.get_alert().dismiss()
                        print u"似乎没有可预订选项"
                        pass
                else:
                    print "can't find orderitem"        
                     
        # b.execute_script('alert("能做的都做了")')
        # b.get_alert().dismiss()
        
        print  u"能做的都做了.....不再对浏览器进行任何操作"
        
    except Exception as e:
        print u"出错了....%s"%e
Пример #32
0
def IsBot(user, follower, link):
    print("\nCHECKING IF {} IS A BOT".format(user))
    global bot
    global nonbot
    global browsers
    global browser_available
    global antidoubler
    global browser
    global primary_count
    
    if IsKnownBot(user):
        print("USER {} IS A BOT".format(user))
        return True
    elif user in nonbot or UserInDB(user):
        statement = ("INSERT INTO Gab.Follows(Follower, Followee)VALUES(%s,%s)")
        values = (user,link) if follower else (link, user)
        if not LinkInDB(values[0], values[1]):
            DBexecuter("insert", statement, values, cursor, cnx)
        return False
    else:
        print("DOING FIRST TIME PROCESSING FOR {}".format(user))
        
        # check if we need to reset browser
        primary_count += 1
        if primary_count >= BROWSE_LIMIT:
            browser.quit()
            
            crawler = Browser('firefox', headless=True)
            crawler.visit("http://gab.ai")
            crawler.driver.implicitly_wait(3)
            
            username = "******"
            password = "******"
            crawler.find_by_name("username").fill(username)
            crawler.find_by_name("password").fill(password)
            crawler.find_by_text("Login")[1].click()
            browser = crawler
            primary_count = 0
            print("PRIMARY BROWSER RESET")
        
        # check if user is bot or not
        page = getHTML("https://gab.ai/" + user)
        soup = BeautifulSoup(page.html, features="html.parser")
        isBot = False
        try:
            # find bio
            bio = soup.find('div', {'class':'profile__bio'})
            # bio message
            bioMessage = bio.find("div").text
            # find metadata
            profileBar = soup.find('div', {'class':'profile__bar'})
            meta = profileBar.findAll('a')
            # number of posts
            numposts = int(meta[1].text.split()[0].replace(',', ''))
            # number of followers
            numfollowers = int(meta[2].text.split()[0].replace(',', ''))
            # number of following
            numfollowing = int(meta[3].text.split()[0].replace(',', ''))
            # perform bot check logic
            if numposts == 0:
                isBot = True
            elif float(numfollowers)/numposts > 100:
                isBot = True
            elif numfollowing != 0 and float(numfollowing)/numposts > 100:
                isBot = True
            elif bioMessage[0] == '"' or bioMessage[0] == "'":
                isBot = True
            elif len(bioMessage.split()) >= 3:
                bioList = bioMessage.split()
                if bioList[-2][0] == '-' or bioList[-3] == '-':
                    isBot = True
        except:
            print("ERROR PARSING USER")
            isBot = True
        # update bot / nonbot
        if isBot:     
            print("USER {} IS A BOT".format(user))
            AddBot(user)
            #bot.add(user)
        else:
            nonbot.add(user)
    
    # if not bot, parse it here and now instead of reloading it
    # if is bot, push name into meta db
    if isBot:
        try:
            print("Adding {} to meta bot DB".format(user))
            statement = """insert into bots (name) values("{}")""".format(user)
            metacursor.execute(statement)
            metacon.commit()
        except:
            print("Failed to add {} to meta bot DB".format(user))
    else: # that is, not isBot
        print("ADDING NEW USER {} TO DATABASE AND SCRAPING POSTS".format(user))
        if not UserInDB(user) and not user in antidoubler:
            try:
                antidoubler.add(user)
                AddUser(user)
                print("GETTING POSTS FOR USER " + user)
                #print("JUST CHECKING... LEN BROWSERS is {}".format(len(browsers)))
                # grab posts here
                # check for an available browser
                while True:
                    found = False
                    for i in range(browser_limit):
                        #print("A - iteration " + str(i))
                        if browser_available[i] == True:
                            found = True
                            #print("B - browser available")
                            browser_available[i] = False
                            #print("C - set browser to unavailable")
                            #p = Process(target=scrapePosts, args=(i, user))
                            p = threading.Thread(target=scrapePosts, args=(i, user))
                            #print("D - process set")
                            threads.append(p)
                            #print("E - appended thread to threads list")
                            p.start()
                            #print("F - started thread")
                            print(user + " IS BEING CRAWLED ON BROWSER " + str(i))
                            break
                    if found:
                        print("DUPLICATE REQUEST IGNORED")
                        break
                    time.sleep(1)
                
            except:
                print("ENCOUNTERED EXCEPTION DOWNLOADING POSTS")
                return isBot
        if UserInDB(user):
            statement = ("INSERT INTO Gab.Follows(Follower, Followee)VALUES(%s,%s)")
            values = (user,link) if follower else (link, user)
            if not LinkInDB(values[0], values[1]):
                DBexecuter("insert", statement, values, cursor, cnx)
    return isBot
Пример #33
0
class TestCase(ptc.PloneTestCase):

    def __init__(self):
        self.browser = Browser(driver_name='firefox')
        self.host, self.port = startZServer()

    def afterSetUp(self):
        self.browser.visit('http://%s:%s/plone' % (self.host, self.port))

    def beforeTearDown(self):
        self.browser.quit()

    def portal_visit(self, url):
        self.browser.visit('http://%s:%s/plone/%s' % (self.host, self.port, url))

    def portal_home(self):
        self.browser.visit('http://%s:%s/plone/' % (self.host, self.port))

    def portal_login(self, user, password):
        self.portal_visit('login_form')
        self.browser.fill('__ac_name', user)
        self.browser.fill('__ac_password', password)
        self.browser.find_by_name('submit').first.click()

    def portal_login_as_owner(self):
        self.portal_login(user=portal_owner, password=default_password)

    def portal_logout(self):
        self.portal_visit('logout')

    def portal_search(self, search_word):
        self.browser.fill('SearchableText','%s' % (search_word))
        self.browser.find_by_css('.searchButton').first.click()

    def portal_navigate_submenu(self, option):
        self.browser.find_by_xpath("//li[contains(@id, 'contentview')]/a[text()='%s']" % (option)).first.click()

    def portal_click_a_personaltool(self, personaltool):
        self.browser.click_link_by_href('http://%s:%s/plone/dashboard' % (self.host, self.port))
        self.browser.click_link_by_text('%s' % (personaltool))

    def portal_add_user(self, fullname, username, email, password):
        self.portal_click_a_personaltool('Site Setup')
        self.browser.click_link_by_text('Users and Groups')
        self.browser.find_by_name('form.button.AddUser').first.click()
        self.browser.fill('form.fullname','%s' % (fullname))
        self.browser.fill('form.username','%s' % (username))
        self.browser.fill('form.email','%s' % (email))
        self.browser.fill('form.password','%s' % (password))
        self.browser.fill('form.password_ctl','%s' % (password))
        self.browser.find_by_id('form.actions.register').first.click()

    def portal_add_user_as_manager(self, fullname, username, email, password):
        self.portal_click_a_personaltool('Site Setup')
        self.browser.click_link_by_text('Users and Groups')
        self.browser.find_by_name('form.button.AddUser').first.click()
        self.browser.fill('form.fullname','%s' % (fullname))
        self.browser.fill('form.username','%s' % (username))
        self.browser.fill('form.email','%s' % (email))
        self.browser.fill('form.password','%s' % (password))
        self.browser.fill('form.password_ctl','%s' % (password))
        self.browser.find_by_id('form.groups.0').first.click()
        self.browser.find_by_id('form.actions.register').first.click()

    def portal_change_user_role(self, username, new_role):
        self.portal_click_a_personaltool('Site Setup')
        self.browser.click_link_by_text('Users and Groups')
        self.browser.find_by_xpath("//tr[*/input[@value='%s']]//input[@value='%s']" % (username, new_role)).first.click()
        self.browser.find_by_name('form.button.Modify').first.click()

    def portal_click_enable_content_types(self):
        self.browser.find_by_css('a[title="Add new items inside this item"]').first.click()

    def portal_add_content_type(self, type):
        self.portal_click_enable_content_types()
        self.browser.click_link_by_text('%s' % (type))

    def portal_click_content_item_action(self):
        self.browser.find_by_css('a[title="Actions for the current content item"]').first.click()

    def portal_add_item_action(self, type):
        self.portal_click_content_item_action()
        self.browser.click_link_by_text('%s' % (type))

    def portal_list_states(self):
        self.browser.find_by_css('a[title="Change the state of this item"]').first.click()

    def portal_modify_state_to(self, state):
        self.portal_list_states()
        self.browser.click_link_by_text('%s' % (state))
Пример #34
0
class TestEngine(object):
    __sleep_time = 2
    __mouse_over = True
    __mouse_over_sleep = 1

    def __init__(self, browser_name, execute_path=None):
        if execute_path is None:
            self.__browser = Browser(browser_name, fullscreen=True)
            self.__quit = False
        else:
            self.__browser = Browser(browser_name, executable_path=execute_path, fullscreen=True)
            self.__quit = False

    @staticmethod
    def set_config(config):
        TestEngine.__sleep_time = 2 if config.get("sleep_time") is None else config.get("sleep_time")
        TestEngine.__mouse_over = True if config.get("mouse_over") is None else config.get("mouse_over")
        TestEngine.__mouse_over_sleep = 1 if config.get("mouse_over_sleep") is None else config.get("mouse_over_sleep")

    def test_list_acts(self, domain, action_list, back_fun=None, result_back=None):
        thread_deal = threading.Thread(target=self.__test_list_thread, args=(domain, action_list, back_fun, result_back), name="TestEngine deal tester")
        thread_deal.start()

    def test_deal(self, domain, action_obj, back_fun=None, result_back=None):
        thread_deal = threading.Thread(target=self.__test_do_thread, args=(domain, action_obj, back_fun, result_back), name="TestEngine deal tester")
        # hasattr(result_back, "__call__")
        thread_deal.start()

    def quit(self):
        self.__quit = True
        self.__browser.quit()

    def is_quited(self):
        return self.__quit

    def __test_list_thread(self, domain, action_list, back_fun=None, result_back=None):
        try:
            for action in action_list:
                self.__test_do(domain, action, result_back)
        except Exception as e:
            raise Exception("[Error code] deal test list failed, error code=", e)
        finally:
            if action_list[0].waitClose != 0:
                sleep(action_list[0].waitClose)

                if back_fun is None:
                    self.quit()
                else:
                    back_fun()


    def __test_do_thread(self, domain, action_obj, back_fun=None, result_back=None):
        try:
            self.__test_do(domain, action_obj, result_back)
        except Exception as e:
            raise Exception("[Error code] deal test failed, error code=", e)
        finally:
            if action_obj.waitClose != 0:
                sleep(action_obj.waitClose)

                if back_fun is None:
                    self.quit()
                else:
                    back_fun()


    def __test_do(self, domain, action_obj, result_back=None):
        test_url = domain+action_obj.urlPath
        self.__browser.visit(test_url)

        # form表单默认为第一个action循环测试,之后的action按照顺序执行
        action_list = TesterActionData().dict_to_list(action_obj.actionList)
        if action_obj.forms is not None:
            form_action = action_list[0] if action_list else None

            forms = TesterForms().dict_to_list(action_obj.forms)
            for form in forms:
                params = TesterFormData().dict_to_list(form.params)
                for param in params:
                    self.__set_value(int(param.formType), param.formElName, param.formElValue.decode("utf-8"), int(param.index))
                    sleep(TestEngine.__sleep_time)

                if form_action is not None:
                    self.__deal_action(form_action, result_back)

                sleep(action_obj.sleepTime)

            for action_deal in action_list[1:]:
                self.__deal_action(action_deal, result_back)
                sleep(action_obj.sleepTime)
        else:
            for action_deal in action_list:
                self.__deal_action(action_deal, result_back)
                sleep(action_obj.sleepTime)


    def __set_value(self, form_type, el_name, el_value, index):
        elements = self.__event_element(form_type, el_name)
        element = elements[index]
        if element['type'] in ['text', 'password', 'tel'] or element.tag_name == 'textarea':
            element.value = el_value
        elif element['type'] == 'checkbox':
            if el_value:
                element.check()
            else:
                element.uncheck()
        elif element['type'] == 'radio':
            element.click()
        elif element._element.tag_name == 'select':
            element.find_by_value(el_value).first._element.click()
        else:
            element.value = el_value


    def __event_element(self, el_type, el_value):
        ele_type = EL_TYPE.value(el_type)

        if ele_type == "id":
            return self.__browser.find_by_id(el_value)
        elif ele_type == "name":
            return self.__browser.find_by_name(el_value)
        elif ele_type == "tag":
            return self.__browser.find_by_tag(el_value)
        elif ele_type == "value":
            return self.__browser.find_by_value(el_value)
        elif ele_type == "selector":
            return self.__browser.find_by_xpath(el_value)
        elif ele_type == "css":
            return self.__browser.find_by_css(el_value)
        else:
            raise ValueError("Test Engine can't deal the element type:%s, el_type:%s", ele_type, el_type)


    def __deal_action(self, action_data, result_back=None):
        action_type = ACTION_TYPE.value(action_data.action)

        # 当页面跳转是抓取最后一个打开的窗口页面
        self.__browser.windows.current = self.__browser.windows[-1]

        if action_type == "click":
            self.__mouse_of_click(self.__event_element(action_data.elType, action_data.elValue)[int(action_data.index)])
        elif action_type == "double click":
            self.__mouse_of_double_click(self.__event_element(action_data.elType, action_data.elValue)[int(action_data.index)])
        elif action_type == "right click":
            self.__mouse_of_right_click(self.__event_element(action_data.elType, action_data.elValue)[int(action_data.index)])
        elif action_type == "mouse over":
            self.__event_element(action_data.elType, action_data.elValue)[int(action_data.index)].mouse_over()
        elif action_type == "mouse out":
            self.__event_element(action_data.elType, action_data.elValue)[int(action_data.index)].mouse_out()
        elif action_type == "select":
            self.__event_element(action_data.elType, action_data.elValue)[int(action_data.index)].select()
        else:
            raise Exception("don't find action for action:%s", action_data.action)

        try:
            if action_data.testerResult is not None and result_back is not None:
                sleep(3)
                result_back(TesterResult(action_data.testerResult, self.__browser.is_text_present(action_data.testerResult)))
        except Exception:
            result_back(TesterResult(action_data.testerResult, False))


    def __mouse_of_click(self, event_deal_obj):
        if TestEngine.__mouse_over:
            event_deal_obj.mouse_over()
            sleep(TestEngine.__mouse_over_sleep)
            event_deal_obj.click()
        else:
            event_deal_obj.click()


    def __mouse_of_right_click(self, event_deal_obj):
        if TestEngine.__mouse_over:
            event_deal_obj.mouse_over()
            sleep(TestEngine.__mouse_over_sleep)
            event_deal_obj.right_click()
        else:
            event_deal_obj.click()


    def __mouse_of_double_click(self, event_deal_obj):
        if TestEngine.__mouse_over:
            event_deal_obj.mouse_over()
            sleep(TestEngine.__mouse_over_sleep)
            event_deal_obj.double_click()
        else:
            event_deal_obj.click()
# do login
browser.find_by_css('.submit-row input').first.click()
# add a new poll
browser.find_link_by_href('polls/poll/add/').first.click()

browser.fill('question', 'Does this test is completed successfully?')
# if you follow the instructions from the tutorial, this is will show
# the datetime options from the poll
browser.find_by_css('.collapse-toggle').first.click()
datetime_fields = browser.find_by_css('.datetimeshortcuts')
datetime_fields[0].find_by_tag('a').first.click()
datetime_fields[1].find_by_tag('a').first.click()
# fill the choices
browser.fill('choice_set-0-choice', 'Yup!')
browser.fill('choice_set-0-votes', '0')
browser.fill('choice_set-1-choice', 'Nope!')
browser.fill('choice_set-1-votes', '0')
browser.fill('choice_set-2-choice', 'Maybe...')
browser.fill('choice_set-2-votes', '0')
# submit the poll
browser.find_by_name('_save').first.click()
# find the poll by the title
browser.find_link_by_text('Does this test is completed successfully?').first.click()
# choose the "delete option"
browser.find_link_by_href('delete/').first.click()
# confirm delete
browser.find_by_css('input[type=submit]').first.click()
# get the result info
print browser.find_by_css('.messagelist').first.text

browser.quit()
Пример #36
0
def scrapePosts(b_index, user):
    global browser_available
    global browsers
    
    print("BROWSER IN USE: " + str(b_index) + " OF " + str(len(browser_available)))
    #print("BROWSERLEN " + str(len(browsers)))
    #browser = browsers[b_index]
    #browser = Browser('firefox')
    #browser.visit("http://gab.ai")
    #browser.driver.implicitly_wait(3)
        
    #username = "******"
    #password = "******"
    #browser.find_by_name("username").fill(username)
    #browser.find_by_name("password").fill(password)
    #print(browser.find_by_text("Login")[1].click())
    
    browser = browsers[b_index]
    
    # reset if necessary
    browser_count[b_index] += 1
    try:
        if browser_count[b_index] >= BROWSE_LIMIT:
            browser.quit()
            
            crawler = Browser('firefox', headless=True)
            crawler.visit("http://gab.ai")
            crawler.driver.implicitly_wait(3)
            
            username = "******"
            password = "******"
            crawler.find_by_name("username").fill(username)
            crawler.find_by_name("password").fill(password)
            crawler.find_by_text("Login")[1].click()
            browsers[b_index] = crawler
            browser_count[b_index] = 0
            print("BROWSER {} RESET".format(b_index))
    except:
        print("failed to reset browser")
        
    browser = browsers[b_index]
    
    
    browser.visit("http://gab.ai/" + user)
    browser.driver.implicitly_wait(3)
    try:
        soup = BeautifulSoup(browser.html, features="html.parser")
    except selenium.common.exceptions.TimeoutException:
        browser_available[b_index] = True
        return AttributeError
    i = 0
    count = 0
    exceptcounter = 0
    try:
        load_count = 0
        while browser.find_by_text("Load more ") and load_count <= LOAD_LIMIT:
            browser.driver.implicitly_wait(1)
            time.sleep(1)
            try:
                browser.find_by_css('.post-list__load-more').click()
                load_count += 1
                soup = BeautifulSoup(browser.html, features="html.parser")
            except Exception:
                exceptcounter += 1
                if exceptcounter == 2:
                    break
                continue
            posts = soup.findAll("post")
            if len(posts) == count:
                break
            count = len(posts)
    except selenium.common.exceptions.WebDriverException:
        browser_available[b_index] = True
        return
    soup = BeautifulSoup(browser.html, features="html.parser")
    postlist = soup.findAll("post")
    for i, post in enumerate(postlist):
        try:
            ScrapAndAddPosts(post, user, b_index)
        except Exception as e:
            error = "FAILED TO PROCESS POST {} FOR USER {}: {}".format(i,user, e)
            print(error)
            errorlog.write(error)
    browser_available[b_index] = True
Пример #37
0
        input_pwd = getpass.getpass('please input password:'******'login fail'
        return
    else:
        insert_user(input_name, input_pwd)
        return 1


login_success = add_version_tag(username, pwd)

if env_id == 'devEnv':
    versionNo = versionNo + '-TEST'

b.fill('tag_name', versionNo)
b.find_by_name('button').click()

# 发布
b.visit('http://sdp.nd/main.html')
time.sleep(0.5)
b.find_by_id('login').click()

username = fetch_username()
pwd = fetch_pwd()

b.find_by_id('object_id').fill(username)
b.find_by_id('password').fill(pwd)
b.find_by_name('keep_pwd')
b.find_by_id('confirmLogin').click()
time.sleep(1)
b.visit('http://sdp.nd/main.html')
Пример #38
0
#!usr/bin/python
from splinter.browser import Browser
import re
import time

br = Browser()
br.visit("http://www.160by2.com/Index")
br.fill('username', 'YOUR_PHONE_NUMBER_USED_TO_CREATE_160BY2_ACCOUNT')
br.fill('password', 'YOUR_ACCOUNT_PASSWORD')
button = br.find_by_name("")
button.click()

stringurl = br.url
stringurl2 = stringurl.split("id=", 1)[1]
id = stringurl2.split("id=", 1)[1]
jsstring = "window.parent.openPage('SendSMS?id=" + id + "', 'aSendSMS', 'aSMS', 'ulSMS')"
br.execute_script(jsstring)
time.sleep(8)
br.execute_script(jsstring)
print "JS Executed"
time.sleep(8)

with br.get_iframe('by2Frame') as iframe:
    iframe.fill(
        "sendSMSMsg",
        "Well, I guess robot's do send SMSes when spandan wants them to ;)")
    iframe.find_by_tag("input")[10].fill(
        "THE_PHONE_NUMBER_YOU_WANT_TO_SEND_SMS_TO")
    button2 = iframe.find_by_id("btnsendsms").first
    print button2.value
    button2.click()
Пример #39
0
def huoche():
    ends = "%u5357%u660C%2CNCG"
    global b
    b = Browser(driver_name="chrome")
    # b = Browser()
    b.visit(ticket_url)
    # b.execute_script('alert("开始刷票喽~~~~")')
    # sleep(2)
    # b.get_alert().dismiss()

    while b.is_text_present(u"登录"):
        sleep(1)
        login()
        if b.url == initmy_url:
            break

    try:
        #跳回购票页面
        b.visit(ticket_url)

        #加载查询信息
        b.cookies.add({"_jc_save_fromStation": starts})
        b.cookies.add({"_jc_save_toStation": ends})
        b.cookies.add({"_jc_save_fromDate": starttime})
        b.cookies.add({"_jc_save_toDate": endtime})
        b.reload()
        i = 1

        b.find_by_name(ttype)[4].click()
        stations = b.find_by_name(fromStation)
        if stations:
            stations[0].click()
        else:
            print "no stations can select"

        #循环点击预订
        if order != 0:
            while b.url == ticket_url:
                print "execute loop order != 0"
                b.find_by_text(u"查询").click()

                if b.find_by_text(u"预订"):
                    sleep(0.3)
                    b.find_by_text(u"预订")[order - 1].click()
                    print b.url

                    if b.is_text_present(u"证件号码", wait_time=0.2):
                        #                        print [ i.text for i in b.find_by_text(pa) ]
                        b.find_by_id("normalPassenger_0").click()
                        b.find_by_id("normalPassenger_1").click()

                else:
                    # b.execute_script('alert("似乎没有可预订选项")')
                    # b.get_alert().dismiss()
                    print "似乎没有可预订选项"
                    pass

        else:
            while b.url == ticket_url:
                print "execute loop order == 0"
                b.find_by_text(u"查询").click()
                if b.find_by_text(u"预订"):
                    sleep(0.3)
                    for i in b.find_by_text(u"预订"):
                        i.click()
                        sleep(0.1)
                        if b.is_text_present(u"证件号码"):
                            # b.find_by_text(pa)[1].click()
                            b.find_by_id("normalPassenger_0").click()
                            b.find_by_id("normalPassenger_1").click()
                            # b.find_by_text("李芷嫣")[0].click()

                    else:
                        # b.execute_script('alert("似乎没有可预订选项")')
                        # b.get_alert().dismiss()
                        print u"似乎没有可预订选项"
                        pass
                else:
                    print "can't find orderitem"

        # b.execute_script('alert("能做的都做了")')
        # b.get_alert().dismiss()

        print u"能做的都做了.....不再对浏览器进行任何操作"

    except Exception as e:
        print u"出错了....%s" % e