#!/usr/bin/python3

import sys,time
import undetected_chromedriver as uc
from selenium.webdriver.common.by import By

options = uc.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')

chrome = uc.Chrome(options=options, version_main=105)
chrome.get(sys.argv[1])
title_element = chrome.find_element(By.XPATH, "//title")
title_str = title_element.get_attribute("innerHTML")

counter = 0
while counter < 150:
	print('title = ' + title_str)
	if title_str.find('Just a moment') != -1:
		time.sleep(10)
		counter = counter + 1
		print('第 ', counter, ' 次重试，继续等待')
		title_element = chrome.find_element(By.XPATH, "//title")
		title_str = title_element.get_attribute("innerHTML")
	else:
		print('success')
		break
html = chrome.page_source
print(title_str)
chrome.quit()
