示例#1
0
def getDemons(name):
    list1 = []
    list0 = []
    start_chrome('https://pointercrate.com/demonlist/')
    press(END)
    press(PAGE_UP)
    click('Open the stats viewer!')
    write(name, into='Enter to search...')
    click(name)
    time.sleep(1)
    main_is_empty = 1
    extended_is_empty = 1
    mainverifs_is_empty = 1
    extendedverifs_is_empty = 1
    for x in range(75):
        counter = x + 1
        if main_is_empty:
            mainlist = find_all(S('//*[@id="beaten"]/b[%d]/a' % (counter)))
        if extended_is_empty:
            extendedlist = find_all(
                S('//*[@id="beaten"]/span[%d]/a' % (counter)))
        if mainverifs_is_empty:
            verifications_main = find_all(
                S('//*[@id="verified"]/b[%d]/a' % (counter)))
        if extendedverifs_is_empty:
            verifications_extended = find_all(
                S('//*[@id="verified"]/span[%d]/a' % (counter)))
        if mainlist == []:
            main_is_empty = 0
        if extendedlist == []:
            extended_is_empty = 0
        if verifications_main == []:
            mainverifs_is_empty = 0
        if verifications_extended == []:
            extendedverifs_is_empty = 0
        list0.append(mainlist)
        list0.append(extendedlist)
        list0.append(verifications_main)
        list0.append(verifications_extended)
    list0 = [element for element in list0 if element != []]
    for demon in list0:
        demon = str(demon)
        start = [m.start() for m in re.finditer(">", demon)][0]
        end = [m.start() for m in re.finditer("<", demon)][1]
        demon = demon[(start + 1):end]
        list1.append(demon)
    kill_browser()
    return list1
示例#2
0
def get_interactive_page_source(url):
    """Obtém código-fonte completo da página."""
    # inicia o chrome para renderizar o código-fonte
    try:
        start_chrome(url, headless=True)
    except Exception:
        print(
            "Erro: você precisa instalar o Google Chrome e o ChromeDriver par"
            "a executar esse raspador.")
        sys.exit(1)

    driver = get_driver()

    # clica em todos os botões "Veja mais!" para liberar os dados dos resumos
    print(
        f"Raspando a página \"{driver.title}\". Isso pode demorar alguns segundos..."
    )
    buttons = find_all(S("//span[@onClick]"))
    for _ in tqdm(range(len(buttons))):
        click("Veja mais!")
    print('Fim da raspagem da página.')

    # obtém objeto soup a partir do código-fonte renderizado pelo helium
    soup = BeautifulSoup(driver.page_source, 'html.parser')

    # fecha o chrome
    kill_browser()

    return soup
示例#3
0
 def test_recover_pass_with_invalid_user(self):
     driver = helium.start_chrome('https://goantifraud.com/manager',
                                  headless=True)
     helium.click('Forgot your password?')
     helium.write(TEST_DATA['invalid_credentials']['log'], into='login')
     helium.click('SEND')
     time.sleep(0.5)
     validation_msg_list = helium.find_all(helium.S(".error.error_show"))
     helium.kill_browser()
     self.assertEqual(len(validation_msg_list), 2)
示例#4
0
	def test_interact_with_found_elements(self):
		all_tfs = find_all(TextField())
		example_tf = None
		for text_field in all_tfs:
			try:
				id_ = text_field.web_element.get_attribute('id')
			except StaleElementReferenceException:
				# This may happen for found web elements in different iframes.
				# TODO: Improve this, eg. by adding a .getId() property to
				# TextField (/HTMLElement) which handles this problem.
				pass
			else:
				if id_ == 'exampleTextFieldId':
					example_tf = text_field
		self.assertIsNotNone(example_tf)
		write("test_interact_with_found_elements", into=example_tf)
		self.assertEqual(
			"test_interact_with_found_elements",
			TextField("Example Text Field").value
		)
 def test_button_no_text(self):
     self.assertEqual(2, len(find_all(Button(to_right_of='Row 1'))))
 def test_list_item_no_text(self):
     all_list_items = find_all(ListItem(below="HTML Unordered List"))
     texts = {list_item.web_element.text for list_item in all_list_items}
     self.assertEqual({'ListItem 1', 'ListItem 2'}, texts)
 def test_link_no_text(self):
     self.assertEqual(4, len(find_all(Link())))
示例#8
0
	def test_find_all_duplicate_button_to_right_of(self):
		self.assertEqual(
			2, len(find_all(Button("Duplicate Button", to_right_of="Row 1")))
		)
示例#9
0
	def test_find_all_duplicate_button(self):
		self.assertEqual(4, len(find_all(Button("Duplicate Button"))))
示例#10
0
	def test_find_all_yields_api_elements(self):
		self.assertIsInstance(
			find_all(TextField('Example Text Field'))[0], TextField
		)
示例#11
0
	def test_find_all_non_existent_button(self):
		self.assertEqual([], find_all(Button("Non-existent Button")))
示例#12
0
	def test_find_all_duplicate_button_below_to_right_of(self):
		self.assertEqual(
			1, len(find_all(Button(
				"Duplicate Button", below="Column 1", to_right_of="Row 1"
			)))
		)
示例#13
0
goods_id = "00718624969"

# family url
family = "https://www.famiport.com.tw/Web_Famiport/page/process.aspx"

# init browser
options = FirefoxOptions()
options.add_argument("--width=800")
options.add_argument("--height=800")
driver = helium.start_firefox(family, options=options)

# wait until web completely loaded
helium.wait_until(helium.Text("※請輸入驗證碼。").exists)

# find all textfield
textfields = helium.find_all(helium.TextField())

# write to the fisrt goods
helium.write(goods_id, into=textfields[2])

# scroll down for viewing verification code and take screenshot
helium.scroll_down(500)
driver.save_screenshot("temp.png")

# read from screen shot as gray image
img = cv2.imread("temp.png", cv2.IMREAD_GRAYSCALE)

# convert to only black and white
ret, img = cv2.threshold(img, 175, 255, cv2.THRESH_BINARY_INV)

# for debug