Example #1
0
def attack_captcha(webdriver, idx):

    now_time = datetime.now().strftime('%s')

    elem = webdriver.find_element_by_xpath('//*[@id="num_img"]')
    url = elem.get_attribute('src')
    f = io.BytesIO(request.urlopen(url).read())
    img = Image.open(f)
    img_path = './img/' + now_time + '.jpg'
    img.save(img_path)
    img_arr = np.asarray(img) / 255

    pre_label = model.predict(img_arr)

    time.sleep(1)

    write = str(pre_label)

    webdriver.find_element_by_xpath('/html/body/form/p[1]/input').send_keys(write)

    print("idx: ", idx, "predict:", write)

    time.sleep(1)

    webdriver.find_element_by_xpath('/html/body/form/p[2]/input').click()

    message = webdriver.find_elements_by_css_selector('p.ans')

    print("idx: ", idx, "message:", message[0].text)

    time.sleep(3)

    webdriver.quit()
def publicAndGeneralCourses(db, cur, tb_campus, area):
    try:
        tbody = WebDriverWait(webdriver, 10).until(
            EC.presence_of_element_located((By.ID, tb_campus)))
    except Exception, e:
        raise e
        webdriver.quit()
        return
Example #3
0
def insta():
    import selenium
    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    USERNAME = str(input("Enetr your user name:"))
    PASSWORD = str(input("Enter Your Password:"))

    chromedriver_path = 'C:/chromedriver.exe'

    webdriver = webdriver.Chrome(executable_path=chromedriver_path)

    webdriver.get(
        'https://www.instagram.com/accounts/login/?source=auth_switcher')
    sleep(5)

    username = webdriver.find_element_by_name('username')
    username.send_keys(USERNAME)
    password = webdriver.find_element_by_name('password')
    password.send_keys(PASSWORD)

    button_login = webdriver.find_element_by_css_selector(
        '#react-root > section > main > div > article > div > div:nth-child(1) > div > form > div:nth-child(4) > button > div'
    )
    button_login.click()
    sleep(6)
    not_now = webdriver.find_element_by_css_selector(
        '#react-root > section > main > div > div > div > div > button')
    not_now.click()
    sleep(6)
    notnow = webdriver.find_element_by_css_selector(
        'body > div.RnEpo.Yx5HN > div > div > div > div.mt3GC > button.aOOlW.HoLwm'
    )
    notnow.click()

    def inbox():
        button_inbox = webdriver.find_element_by_css_selector(
            '#react-root > section > nav > div._8MQSO.Cx7Bp > div > div > div.ctQZg > div > div:nth-child(2) > a > svg'
        )
        button_inbox.click()
        sleep(10)
        button_home = webdriver.find_element_by_css_selector(
            '#react-root > section > div > div._lz6s.Hz2lF > div > div.ctQZg > div > div:nth-child(1) > div > a > svg'
        )
        button_home.click()

    inbox()
    sleep(10)

    def activity():
        button_activity = webdriver.find_element_by_css_selector(
            '#react-root > section > nav > div._8MQSO.Cx7Bp > div > div > div.ctQZg > div > div:nth-child(4) > a > svg'
        )
        button_activity.click()
        sleep(2)

    activity()

    webdriver.quit()
Example #4
0
 def hook_close_window():
     chrome_close = False
     while not chrome_close:
         time.sleep(.3) # 每0.3秒检测一次,如果强制关闭浏览器,则自动关闭 chromedriver.exe
         try:    driver_logs = webdriver.get_log('driver')
         except: driver_logs = []
         for i in driver_logs:
             if 'Unable to evaluate script: disconnected: not connected to DevTools' in i.get('message'):
                 chrome_close = True
                 webdriver.quit()
def take_screenshot(url):
    try:
        webdriver = selenium.webdriver.PhantomJS('vendor/phantomjs/bin/phantomjs')
        webdriver.get(url)
        webdriver.set_window_size(1280,800)
        imagedata = webdriver.get_screenshot_as_base64()
        webdriver.close()
        webdriver.quit()
    except Exception, e:
        raise
Example #6
0
 def hook_close_window():
     chrome_close = False
     while not chrome_close:
         time.sleep(.3)  # 每0.3秒检测一次
         driver_logs = webdriver.get_log('driver')
         for i in driver_logs:
             if 'Unable to evaluate script: disconnected: not connected to DevTools' in i.get(
                     'message'):
                 chrome_close = True
                 webdriver.quit()
                 print('webdriver is closed.')
Example #7
0
    def scanCampsite(self, siteNumber):
        self._verifyDates()
        isAvailable = False
        webdriver = self._setUpDriver(siteNumber)
        html = webdriver.page_source
        webdriver.quit()
        soup = BeautifulSoup(html, 'html.parser')
        bookingBtn = soup.find(id='add-cart-campsite').span.span.string
        if str(bookingBtn).find("Booking") != -1:
            isAvailable = True

        return isAvailable
Example #8
0
def form(link, webdriver):
    try:

        webdriver.get(link)
        form_data(webdriver)

    finally:
        # успеваем скопировать код за 30 секунд
        time.sleep(5)
        # закрываем браузер после всех манипуляций
        webdriver.quit()

    return
Example #9
0
 def tistory_post(self, blog_name, title, content, category):
     webdriver = Chrome(self.chromedriver_path)
     response = webdriver.request('POST',
                                  'https://www.tistory.com/apis/post/write',
                                  data={
                                      "access_token": self.tistory_token,
                                      "blogName": blog_name,
                                      'title': title,
                                      'content': content,
                                      'category': category,
                                      'visibility': '2'
                                  })
     webdriver.quit()
     print(response)
Example #10
0
def form(url, string, webdriver):
    try:

        webdriver.get(url)
        clink = webdriver.find_element_by_partial_link_text(string)
        clink.click()
        time.sleep(2)
        submit_web_form.form_data(webdriver)

    finally:
        # успеваем скопировать код за 10 секунд
        time.sleep(10)
        # закрываем браузер после всех манипуляций
        webdriver.quit()
    return
Example #11
0
 def clean_up_webdrivers():
     '''
     Clean up webdrivers created during execution.
     '''
     # Quit webdrivers.
     print "Cleaning up webdrivers"
     try:
         if WebDriverManager.__use_shutdown_hook:
             for webdriver in WebDriverManager.__webdrivers_created:
                 try:
                     webdriver.quit()
                 except Exception as e:
                     print e
     except:
         pass
Example #12
0
def get_results_by_year(webdriver, input_file):
    login(webdriver)
    response_files_by_year = {}
    submenus = [
        submenu.get_attribute('id')
        for submenu in webdriver.find_elements_by_xpath(
            "//div[@id='menugroup_4']/div[not(@id='menugroup_4_1')]")
    ]
    for submenu_id in submenus:
        year = send_request_file(webdriver, submenu_id, input_file)
        time.sleep(10)
        file = download_response_file(webdriver)
        if (file):
            response_files_by_year[year] = file
        webdriver.implicitly_wait(2)
    time.sleep(3)
    webdriver.quit()
    return response_files_by_year
Example #13
0
def main():
    webdriver = get_webdriver()
    data = webdriver.find_element_by_id(
        "ctl00_contentPlaceHolderConteudo_lblTitulo").text
    data = data.split('Carteira Teórica do Ibovespa válida para ')[1]
    date_object = datetime.strptime(data, '%d/%m/%y').date()
    print(date_object)

    table_content = webdriver.find_element_by_id(
        'ctl00_contentPlaceHolderConteudo_grdResumoCarteiraTeorica_ctl00'
    ).get_attribute('innerHTML')

    # Fecha navegador
    webdriver.quit()

    dados = fetch_portfolio_composition(table_content)
    for row in dados:
        print(row[1])
Example #14
0
 def teardown(self):
     webdriver.quit()
Example #15
0
 def cleanup_webdriver(self, webdriver=None):
     try:
         webdriver.quit()
         webdriver.close()
     except Exception:
         pass
Example #16
0
def quit_driver(webdriver):
    webdriver.close()
    webdriver.quit()
Example #17
0
def finaliza_spider(webdriver):
    webdriver.quit()
    with get_log_file() as f:
        f.write("[INFO] Spider finalizada.\n")
Example #18
0
 def teardown(self):
     webdriver.quit()
Example #19
0
 def driver_quit(webdriver):
     webdriver.quit()
Example #20
0
dr.get(url)

sl(2)
st = dr.find_element_by_link_text("设置")
st.click()
ss = dr.find_element_by_link_text("搜索设置")
ss.click()
sl(2)

hp = dr.find_element_by_id("sh_2")
hp.click()
sl(2)

#bc = dr.find_element_by_link_text("保存设置")
bc = dr.find_element_by_xpath("//div[@id='gxszButton']/a[1]")
bc.click()
sl(2)

#切换到ALTER弹窗
alt = dr.switch_to.alert
#获取弹窗文本
tx = alt.text
print("获取弹窗文本: " + str(tx))
#确认
#alt.accept()
#取消
alt.dismiss()

sl(3)
dr.quit()
Example #21
0
from selenium import webdriver
import time

webdriver = webdriver.Chrome(executable_path="C:\Drivers\chromedriver.exe")
#webdriver = webdriver.Firefox( executable_path= "C:\Drivers\geckodriver.exe")
#webdriver = webdriver.Ie(executable_path= "C:\Drivers\IEDriverServer")
#webdriver.get("https://www.amazon.com/")

webdriver.get("http://demo.automationtesting.in/Windows.html")

print(webdriver.title)  #returns the title of the page
print(webdriver.current_url)  #returns URL of the page

webdriver.find_element_by_xpath('//*[@id="Tabbed"]/a/button').click()

time.sleep(5)

#print(webdriver.page_source) #HTML code for the page (huge information)

#webdriver.close()  #closes only currently focussed browser tab
webdriver.quit()  #closes all tabs of the browser
Example #22
0
def tistory_post(token, title, content, category):
    webdriver = Chrome()
    response = webdriver.request('POST', 'https://www.tistory.com/apis/post/write', data={"access_token": token, "blogName": "sfixer", 'title': title, 'content': content, 'category': category, 'visibility': '2'})
    webdriver.quit()
    print(response)
Example #23
0
File: 123.py Project: ban666/prj
# -*- coding:gb2312 -*-
from selenium import webdriver
from info import ip
from info import pwd
from info import base_url
from time import sleep
import sys
import ssh
import web
import os
        

try:
    a=web.TimeGroupAdd(base_url)
    print a
    webdriver.quit();
except:
    print 0               
    webdriver.quit();
Example #24
0
def tearDownBrowser(browser, webdriver):
    print("-------------------------------------")
    print("Run " + browser + " Completed at :" + str(datetime.datetime.now()))
    webdriver.close()
    webdriver.quit()
Example #25
0
 def tearDown(self):
     self.browser = webdriver.quit()
Example #26
0
from selenium import webdriver
import time

webdriver = webdriver.Chrome(executable_path=("C:\Drivers\chromedriver.exe"))

webdriver.get('https://www.onliner.by/')  #Get URL
sign_in = webdriver.find_element_by_xpath(
    '//*[@id="userbar"]/div[2]/div/div/div[1]').click(
    )  #Find and Click on Sign_in Button

email = webdriver.find_element_by_xpath(
    '//*[@id="auth-container"]/div/div[2]/div/form/div[1]/div/div[2]/div/div/div/div/input'
)  #To get email field
email.send_keys('*****@*****.**')  #Enter your email
time.sleep(2)  #Waiting

password = webdriver.find_element_by_xpath(
    "//*[@id='auth-container']/div/div[2]/div/form/div[2]/div/div/div/div/input"
)  #To get password field
password.send_keys('*****@*****.**')  #Enter your password
time.sleep(2)

webdriver.find_element_by_xpath(
    '//*[@id="auth-container"]/div/div[2]/div/form/div[3]/button').click(
    )  #Click on the Sign-in Button and Go to Home Page

time.sleep(3)
webdriver.quit()  #Closing
Example #27
0
import math

link = "http://suninjuly.github.io/explicit_wait2.html"


def calc(x):
    return str(math.log(abs(12 * math.sin(int(x)))))


try:
    webdriver = webdriver.Chrome()
    webdriver.get(link)
    #wait 5 sec for each element
    webdriver.implicitly_wait(5)
    #WebDriverWait и expected_conditions)
    price = WebDriverWait(webdriver, 12).until(
        EC.text_to_be_present_in_element((By.ID, "price"), "$100"))
    book = webdriver.find_element_by_id("book")
    book.click()

    x = webdriver.find_element_by_id("input_value").text
    y = calc(x)

    input_field = webdriver.find_element_by_id('answer').send_keys(y)

    submit = webdriver.find_element_by_id('solve').click()

finally:
    time.sleep(5)
    webdriver.quit()
def after_scenario(context, scenario):
    context.browser = webdriver.quit()