page viewer: fix 'empty range for randrange() (0, 0, 0)'
when no clickable elements are foundmaster
parent
2161f4ba01
commit
cd12419b47
|
@ -52,12 +52,12 @@ def visit_page(driver, url):
|
||||||
|
|
||||||
def try_to_click_elements(driver, clickable_elements):
|
def try_to_click_elements(driver, clickable_elements):
|
||||||
while True:
|
while True:
|
||||||
index = random.randint(0, len(clickable_elements) - 1)
|
|
||||||
|
|
||||||
if len(clickable_elements) == 0:
|
if len(clickable_elements) == 0:
|
||||||
print("All the elements weren't clickable!")
|
print("All the elements weren't clickable!")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
index = random.randint(0, len(clickable_elements) - 1)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print("trying to click element", clickable_elements[index])
|
print("trying to click element", clickable_elements[index])
|
||||||
clickable_elements[index].click()
|
clickable_elements[index].click()
|
||||||
|
@ -70,7 +70,7 @@ def try_to_click_elements(driver, clickable_elements):
|
||||||
def get_clickable_ads(driver):
|
def get_clickable_ads(driver):
|
||||||
searchable_ads = [frame for frame in driver.find_elements_by_xpath('.//iframe') ]
|
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() ]
|
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
|
return id_ok_ads
|
||||||
|
|
||||||
|
@ -122,8 +122,8 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
if len(threads) < NO_PROCESSES:
|
if len(threads) < NO_PROCESSES:
|
||||||
print(f"[BOT] Starting thread n.{len(threads)}/{NO_PROCESSES}")
|
print(f"[BOT] Starting thread n.{len(threads)+1}/{NO_PROCESSES}")
|
||||||
t1 = threading.Thread(target=launch_and_visit, args=(False, 'https://giangillorossi.altervista.org', False))
|
t1 = threading.Thread(target=launch_and_visit, args=(True, 'https://giangillorossi.altervista.org', True))
|
||||||
t1.start()
|
t1.start()
|
||||||
|
|
||||||
threads.append(t1)
|
threads.append(t1)
|
||||||
|
@ -132,7 +132,7 @@ if __name__ == "__main__":
|
||||||
while i < len(threads):
|
while i < len(threads):
|
||||||
# print(i)
|
# print(i)
|
||||||
if not (threads[i].is_alive()):
|
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)
|
threads.pop(i)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue