Spaces:
Sleeping
Sleeping
Create worker.py
Browse files
worker.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from playwright.sync_api import sync_playwright
|
| 2 |
+
|
| 3 |
+
def get_operator(phone_number: str) -> str:
|
| 4 |
+
with sync_playwright() as p:
|
| 5 |
+
browser = p.chromium.launch(
|
| 6 |
+
headless=True,
|
| 7 |
+
args=[
|
| 8 |
+
"--no-sandbox",
|
| 9 |
+
"--disable-setuid-sandbox",
|
| 10 |
+
"--disable-gpu",
|
| 11 |
+
"--disable-dev-shm-usage",
|
| 12 |
+
"--no-zygote"
|
| 13 |
+
]
|
| 14 |
+
)
|
| 15 |
+
context = browser.new_context()
|
| 16 |
+
page = context.new_page()
|
| 17 |
+
|
| 18 |
+
page.goto('https://paytm.com/recharge', wait_until='networkidle')
|
| 19 |
+
page.wait_for_selector('input[type="tel"]')
|
| 20 |
+
page.fill('input[type="tel"]', phone_number)
|
| 21 |
+
|
| 22 |
+
page.wait_for_function("""
|
| 23 |
+
() => {
|
| 24 |
+
const el = document.querySelector('div._1exI input[type="text"]');
|
| 25 |
+
return el && el.value && el.value.trim().length > 0;
|
| 26 |
+
}
|
| 27 |
+
""", timeout=15000)
|
| 28 |
+
|
| 29 |
+
operator = page.eval_on_selector('div._1exI input[type="text"]', 'el => el.value')
|
| 30 |
+
browser.close()
|
| 31 |
+
return operator
|