Update app.py
Browse files
app.py
CHANGED
|
@@ -25,7 +25,7 @@ def setup_driver():
|
|
| 25 |
chrome_options.add_argument('--disable-dev-shm-usage')
|
| 26 |
chrome_options.add_argument('--disable-gpu')
|
| 27 |
chrome_options.add_argument('--disable-software-rasterizer')
|
| 28 |
-
chrome_options.add_argument('--headless')
|
| 29 |
chrome_options.add_argument('--disable-blink-features=AutomationControlled')
|
| 30 |
chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
|
| 31 |
chrome_options.add_experimental_option('useAutomationExtension', False)
|
|
@@ -42,15 +42,12 @@ def get_verification_code(driver, email, max_retries=10, delay=2):
|
|
| 42 |
|
| 43 |
for attempt in range(max_retries):
|
| 44 |
try:
|
| 45 |
-
# 刷新页面获取最新邮件
|
| 46 |
driver.refresh()
|
| 47 |
time.sleep(delay)
|
| 48 |
|
| 49 |
-
# 尝试获取邮件内容
|
| 50 |
body_content = driver.find_element(By.CLASS_NAME, "body").get_attribute('outerHTML')
|
| 51 |
logger.info(f"获取到邮件内容: {body_content}")
|
| 52 |
|
| 53 |
-
# 匹配验证码
|
| 54 |
match = re.search(r'\b\d{6}\b', body_content)
|
| 55 |
if match:
|
| 56 |
verification_code = match.group(0)
|
|
@@ -122,14 +119,6 @@ with gr.Blocks(title="邮箱验证码服务") as demo:
|
|
| 122 |
with gr.Row():
|
| 123 |
email_btn = gr.Button("生成邮箱", variant="primary")
|
| 124 |
email_output = gr.JSON(label="结果")
|
| 125 |
-
|
| 126 |
-
gr.Examples(
|
| 127 |
-
examples=[],
|
| 128 |
-
inputs=[],
|
| 129 |
-
outputs=[email_output],
|
| 130 |
-
fn=generate_random_email,
|
| 131 |
-
cache_examples=True,
|
| 132 |
-
)
|
| 133 |
|
| 134 |
with gr.Tab("获取验证码"):
|
| 135 |
with gr.Row():
|
|
|
|
| 25 |
chrome_options.add_argument('--disable-dev-shm-usage')
|
| 26 |
chrome_options.add_argument('--disable-gpu')
|
| 27 |
chrome_options.add_argument('--disable-software-rasterizer')
|
| 28 |
+
chrome_options.add_argument('--headless')
|
| 29 |
chrome_options.add_argument('--disable-blink-features=AutomationControlled')
|
| 30 |
chrome_options.add_experimental_option('excludeSwitches', ['enable-automation'])
|
| 31 |
chrome_options.add_experimental_option('useAutomationExtension', False)
|
|
|
|
| 42 |
|
| 43 |
for attempt in range(max_retries):
|
| 44 |
try:
|
|
|
|
| 45 |
driver.refresh()
|
| 46 |
time.sleep(delay)
|
| 47 |
|
|
|
|
| 48 |
body_content = driver.find_element(By.CLASS_NAME, "body").get_attribute('outerHTML')
|
| 49 |
logger.info(f"获取到邮件内容: {body_content}")
|
| 50 |
|
|
|
|
| 51 |
match = re.search(r'\b\d{6}\b', body_content)
|
| 52 |
if match:
|
| 53 |
verification_code = match.group(0)
|
|
|
|
| 119 |
with gr.Row():
|
| 120 |
email_btn = gr.Button("生成邮箱", variant="primary")
|
| 121 |
email_output = gr.JSON(label="结果")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
|
| 123 |
with gr.Tab("获取验证码"):
|
| 124 |
with gr.Row():
|