page viewer: fix 'empty range for randrange() (0, 0, 0)'
when no clickable elements are foundmaster
parent
2161f4ba01
commit
cd12419b47
|
@ -47,17 +47,17 @@ def visit_page(driver, url):
|
|||
if try_to_click_elements(driver, get_clickable_ads(driver)):
|
||||
time.sleep(4)
|
||||
break
|
||||
|
||||
|
||||
driver.quit()
|
||||
|
||||
def try_to_click_elements(driver, clickable_elements):
|
||||
while True:
|
||||
index = random.randint(0, len(clickable_elements) - 1)
|
||||
|
||||
if len(clickable_elements) == 0:
|
||||
print("All the elements weren't clickable!")
|
||||
return False
|
||||
|
||||
index = random.randint(0, len(clickable_elements) - 1)
|
||||
|
||||
try:
|
||||
print("trying to click element", clickable_elements[index])
|
||||
clickable_elements[index].click()
|
||||
|
@ -70,7 +70,7 @@ def try_to_click_elements(driver, clickable_elements):
|
|||
def get_clickable_ads(driver):
|
||||
searchable_ads = [frame for frame in driver.find_elements_by_xpath('.//iframe') ]
|
||||
id_ok_ads = [frame for frame in searchable_ads if ('ad' in frame.get_attribute('id') or 'google_ad' in frame.get_attribute('id')) and frame.is_displayed() ]
|
||||
print(id_ok_ads)
|
||||
print(f"Ads that can be clicked {id_ok_ads}")
|
||||
|
||||
return id_ok_ads
|
||||
|
||||
|
@ -122,8 +122,8 @@ if __name__ == "__main__":
|
|||
|
||||
while True:
|
||||
if len(threads) < NO_PROCESSES:
|
||||
print(f"[BOT] Starting thread n.{len(threads)}/{NO_PROCESSES}")
|
||||
t1 = threading.Thread(target=launch_and_visit, args=(False, 'https://giangillorossi.altervista.org', False))
|
||||
print(f"[BOT] Starting thread n.{len(threads)+1}/{NO_PROCESSES}")
|
||||
t1 = threading.Thread(target=launch_and_visit, args=(True, 'https://giangillorossi.altervista.org', True))
|
||||
t1.start()
|
||||
|
||||
threads.append(t1)
|
||||
|
@ -132,7 +132,7 @@ if __name__ == "__main__":
|
|||
while i < len(threads):
|
||||
# print(i)
|
||||
if not (threads[i].is_alive()):
|
||||
print(f"[BOT] Thread n.{i} has stopped, removing from list")
|
||||
print(f"[BOT] Thread n.{i+1} has stopped, removing from list")
|
||||
threads.pop(i)
|
||||
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue