def pageTest(): driver = getChromeDriver() #driver = getChromeHeadlessDriver() try: page = GooglePage(driver) """ driver = getChromeHeadlessDriver() page = GooglePage(driver) page = QuickRefSelectPage(driver) page = QuickRefRadioPage(driver) page = QuickRefCheckboxPage(driver) page = DocsApplyPage(driver) page = ApplyPage(driver) page = DocsApplyPage(driver) """ page.test() time.sleep(3) # wait for page transition #fullScreen(driver) driver.set_window_size(1920, 4000) screenShot(driver, 'test') print('finished') except Exception as e: print(traceback.format_exc()) driver.set_window_size(1920, 4000) screenShot(driver, 'failure') finally: pass
def getForm(): driver = getChromeDriver() #driver = getChromeHeadlessDriver() try: driver.get(url) tags = getFormItems(driver) tags = list(filter(lambda tag: tag['type'] != 'hidden', tags)) createCsv(tags) except Exception as e: print(traceback.format_exc()) finally: driver.close() driver.quit()
def analizer(): #url = "https://google.com" url = "https://qiita.com/yoshi0518/items/14690172f41c32c8286b" driver = getChromeDriver() try: analizer = Analizer(driver, url) data = analizer.getLinks() error = '' except Exception as e: data = {} error = traceback.format_exc() finally: driver.close() driver.quit() return render_template('analizer.html', data=data, error=error)
def testSample(): user = '******' password = '******' url = 'https://qiita.com/mochio/items/dc9935ee607895420186' imageTitle = 'xxx' # launch browser driver = getChromeDriver() try: # open page driver.get(url) imageTitle = driver.title footer = driver.find_element_by_xpath('/html/body/footer') inputBirthYear = driver.find_element_by_name('birth_year') Select(inputBirthYear).select_by_value('2010') inputBirthYear = driver.find_element_by_name('birth_month') Select(inputBirthYear).select_by_value('10') inputBirthYear = driver.find_element_by_name('birth_day') Select(inputBirthYear).select_by_value('09') sleep(1) actions = ActionChains(driver) actions.move_to_element(footer) actions.perform() #inputSchool = driver.find_element_by_xpath('//*[@id="school"]/div/label[1]/p') inputSchool = driver.find_element_by_xpath( '//*[@id="school"]/div/label[1]/input') inputSchool.click() screenShot(driver, imageTitle) except Exception as e: sys.exc_info() finally: # close driver.close() driver.quit()
def label(): driver = getChromeDriver() page = QuickRefLabelPage(driver) return test(driver, page)
def shinro(): driver = getChromeDriver() page = DocsApplyPage(driver) return test(driver, page)
def checkbox(): driver = getChromeDriver() page = QuickRefCheckboxPage(driver) return test(driver, page)
def radio(): driver = getChromeDriver() page = QuickRefRadioPage(driver) return test(driver, page)
def select(): driver = getChromeDriver() page = QuickRefSelectPage(driver) return test(driver, page)
def google(): driver = getChromeDriver() page = GooglePage(driver) return test(driver, page)
def capture(): # initialize vars data = {} error = '' docker_host_url = Conf.getDockerHostUtl() if request.method == 'POST': url, xpath, title = request.form['url'], request.form['xpath'], 'test' data['url'] = url data['xpath'] = xpath driver = getChromeDriver() #driver = getChromeHeadlessDriver() try: driver.get(url) fullScreen(driver) sleep(5) """refered: https://qiita.com/happou/items/5b7072d145a974380787""" img_base64 = driver.get_screenshot_as_base64() img_data = base64.b64decode(img_base64) img_np = np.fromstring(img_data, np.uint8) wholeImg = cv2.imdecode(img_np, cv2.IMREAD_ANYCOLOR) elements = driver.find_elements('xpath', xpath) ss = [] marks = [] for element in elements: if element.is_displayed() == False: print('skip invisible element') continue """画像リンクやラベル付きinputの領域をelementから判別しようとしたが、処理が重くなったのでxpathで調整する設計とする""" rect = element.rect xStart = math.floor(rect['x']) yStart = math.floor(rect['y']) xEnd = math.floor(rect['x'] + rect['width']) yEnd = math.floor(rect['y'] + rect['height']) elemImg = wholeImg[yStart:yEnd, xStart:xEnd] if elemImg is None or elemImg.shape[ 0] == 0 or elemImg.shape[1] < 10: print('OVER LIMIT') print(element.text) print( str(yStart) + ', ' + str(yEnd) + ', ' + str(xStart) + ', ' + str(xEnd)) continue """refered: https://gist.github.com/gachiemchiep/52f3255a81c907461c2c7ced6ede367a""" retval, buffer = cv2.imencode('.png', elemImg) elem_bytes = np.array(buffer).tostring() b64E = base64.b64encode(elem_bytes).decode('utf-8') # ファイルに保存していると不要ファイルが増えて煩わしかった #cv2.imwrite(destPath, elemImg) #with open(destPath, "rb") as image_file: # b64E = base64.b64encode(image_file.read()).decode('utf-8') # バイナリストリームに保存するアイデアもあったがうまく動かせなかった #with io.BytesIO() as memory: # cv2.imwrite(memory, elemImg) # BinStE = memory.getvalue() #b64E = base64.b64encode(BinStE).decode('utf-8') ss.append(b64E) marks.append({ 'xStart': xStart, 'yStart': yStart, 'xEnd': xEnd, 'yEnd': yEnd }) img, text, org = wholeImg, url, (10, 20) fotFace, fontScale, color, thickness, lineType = cv2.FONT_HERSHEY_SIMPLEX, 0.5, ( 0, 0, 0), 1, cv2.LINE_AA cv2.putText(img, text, org, fotFace, fontScale, color, thickness, lineType) for i, mark in enumerate(marks): xStart, yStart, xEnd, yEnd = mark['xStart'], mark[ 'yStart'], mark['xEnd'], mark['yEnd'] # 囲み wholeImg = cv2.rectangle(wholeImg, (xStart, yStart), (xEnd, yEnd), (0, 0, 255), 3) for i, mark in enumerate(marks): xStart, yStart, xEnd, yEnd = mark['xStart'], mark[ 'yStart'], mark['xEnd'], mark['yEnd'] # ナンバリング radius = 8 wholeImg = cv2.circle(wholeImg, ((xEnd + radius + 2), (yEnd - radius + 2)), radius, (64, 64, 64), (radius * 2)) img, text, org = wholeImg, str(i + 1).zfill(2), (xEnd, yEnd) fotFace, fontScale, color, thickness, lineType = cv2.FONT_HERSHEY_SIMPLEX, 0.5, ( 255, 255, 255), 1, cv2.LINE_AA cv2.putText(img, text, org, fotFace, fontScale, color, thickness, lineType) retval, buffer = cv2.imencode('.png', wholeImg) elem_bytes = np.array(buffer).tostring() b64E = base64.b64encode(elem_bytes).decode('utf-8') data['report'] = b64E data['ss'] = ss except Exception as e: error = traceback.format_exc() finally: driver.close() driver.quit() return render_template('capture.html', data=data, error=error, docker_host_url=docker_host_url, randamInt=random.randrange(1, 65535))