Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,85 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
wget gnupg unzip curl \
|
5 |
-
chromium chromium-driver \
|
6 |
-
fonts-liberation \
|
7 |
-
&& rm -rf /var/lib/apt/lists/*
|
8 |
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
|
13 |
-
WORKDIR /app
|
14 |
-
RUN pip install --no-cache-dir -r requirements.txt
|
15 |
|
16 |
-
|
17 |
|
18 |
-
|
|
|
|
|
19 |
|
20 |
-
#
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
from selenium import webdriver
|
3 |
+
from selenium.webdriver.chrome.options import Options
|
4 |
+
from selenium.webdriver.common.by import By
|
5 |
+
from bs4 import BeautifulSoup
|
6 |
+
import time
|
7 |
|
8 |
+
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
def get_hidden_code(url):
|
11 |
+
chrome_options = Options()
|
12 |
+
chrome_options.add_argument("--headless=new")
|
13 |
+
chrome_options.add_argument("--no-sandbox")
|
14 |
+
chrome_options.add_argument("--disable-dev-shm-usage")
|
15 |
+
chrome_options.add_argument("--disable-gpu")
|
16 |
+
chrome_options.add_argument("--disable-software-rasterizer")
|
17 |
+
chrome_options.add_argument("--incognito")
|
18 |
+
chrome_options.add_argument("--remote-debugging-port=9222")
|
19 |
|
20 |
+
driver = webdriver.Chrome(options=chrome_options)
|
|
|
|
|
21 |
|
22 |
+
token_found = []
|
23 |
|
24 |
+
try:
|
25 |
+
driver.get(url)
|
26 |
+
time.sleep(3)
|
27 |
|
28 |
+
# Try clicking the button
|
29 |
+
try:
|
30 |
+
start_button = driver.find_element(By.XPATH, "//button[contains(text(), 'Start Challenge')]")
|
31 |
+
start_button.click()
|
32 |
+
time.sleep(3)
|
33 |
+
except Exception as e:
|
34 |
+
print("⚠️ Could not click Start Challenge button:", e)
|
35 |
+
|
36 |
+
html = driver.page_source
|
37 |
+
soup = BeautifulSoup(html, "html.parser")
|
38 |
+
|
39 |
+
# Scrape hidden elements
|
40 |
+
for tag in soup.find_all(True):
|
41 |
+
if tag.has_attr("style") and "display:none" in tag["style"]:
|
42 |
+
token_found.append(tag.get_text(strip=True))
|
43 |
+
|
44 |
+
for hidden in soup.find_all("input", {"type": "hidden"}):
|
45 |
+
if hidden.get("value"):
|
46 |
+
token_found.append(hidden["value"])
|
47 |
+
|
48 |
+
if "hidden code" in html.lower():
|
49 |
+
start = html.lower().find("hidden code")
|
50 |
+
token_found.append(html[start:start+100])
|
51 |
+
|
52 |
+
driver.quit()
|
53 |
+
return list(set(token_found)) or ["No hidden code found"]
|
54 |
+
|
55 |
+
except Exception as e:
|
56 |
+
driver.quit()
|
57 |
+
return [f"Error: {str(e)}"]
|
58 |
+
|
59 |
+
@app.route("/mission", methods=["POST"])
|
60 |
+
def mission():
|
61 |
+
data = request.json
|
62 |
+
url = data.get("url")
|
63 |
+
questions = data.get("questions", [])
|
64 |
+
|
65 |
+
if not url:
|
66 |
+
return jsonify({"error": "URL is required"}), 400
|
67 |
+
|
68 |
+
tokens = get_hidden_code(url)
|
69 |
+
|
70 |
+
print("\n===== Mission Request =====")
|
71 |
+
print("URL received:", url)
|
72 |
+
print("Questions received:", questions)
|
73 |
+
print("Token(s) found:", tokens)
|
74 |
+
print("===========================\n")
|
75 |
+
|
76 |
+
return jsonify({
|
77 |
+
"url_received": url,
|
78 |
+
"questions_received": questions,
|
79 |
+
"token_found": tokens
|
80 |
+
})
|
81 |
+
|
82 |
+
if __name__ == "__main__":
|
83 |
+
import os
|
84 |
+
port = int(os.environ.get("PORT", 7860))
|
85 |
+
app.run(host="0.0.0.0", port=port, debug=False)
|