Created
August 20, 2019 06:57
-
-
Save Saren-Arterius/89a5537aa00866d8b8a0195015bd1194 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities | |
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary | |
from time import sleep | |
import threading | |
caps = DesiredCapabilities().FIREFOX | |
#caps["pageLoadStrategy"] = "normal" # complete | |
caps["pageLoadStrategy"] = "eager" # interactive | |
#caps["pageLoadStrategy"] = "none" | |
binary = FirefoxBinary('/usr/bin/firefox') | |
lolz = ['temporarily unavailable', 'a large number of customers', 'busy.aegpromotion.com', 'Traffic blocked'] | |
lolz_count = [0, 0, 0, 0, 0] | |
count = 0 | |
threads = 16 | |
ok = False | |
def job(): | |
global count, ok | |
driver = webdriver.Firefox(desired_capabilities=caps, firefox_binary=binary) | |
driver.set_page_load_timeout(10) | |
while True: | |
if ok: | |
driver.quit() | |
return | |
while True: | |
try: | |
count += 1 | |
driver.get("http://aegpromotion.com/eason2019/") | |
break | |
except Exception as e: | |
print(e) | |
if 'Timeout' not in repr(e): | |
raise e | |
ps = driver.page_source | |
m = list(map(lambda s: s in ps, lolz)) | |
empty = len(ps) == 0 | |
result = empty or any(m) | |
if result: | |
if empty: | |
lolz_count[-1] += 1 | |
for i, b in enumerate(m): | |
if b: | |
lolz_count[i] += 1 | |
print(count, lolz_count, end="\r") | |
continue | |
print(driver.page_source) | |
break | |
ok = True | |
sleep(100000000) | |
if __name__ == "__main__": | |
for i in range(100000000): | |
if ok: | |
break | |
if threading.active_count() > threads: | |
sleep(1) | |
continue | |
t = threading.Thread(target = job) | |
print('Staring thread', i) | |
t.start() | |
sleep(100000000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment