|
@@ -0,0 +1,36 @@
|
|
|
|
|
+from flask import Flask, request, render_template_string
|
|
|
|
|
+from selenium import webdriver
|
|
|
|
|
+from selenium.webdriver.chrome.options import Options
|
|
|
|
|
+from selenium.webdriver.common.by import By
|
|
|
|
|
+import os, time
|
|
|
|
|
+
|
|
|
|
|
+SELENIUM_URL = os.getenv("SELENIUM_URL","http://localhost:4444/wd/hub")
|
|
|
|
|
+app = Flask(__name__)
|
|
|
|
|
+
|
|
|
|
|
+HTML = """<h1>Upload</h1>
|
|
|
|
|
+<form method=post enctype=multipart/form-data>
|
|
|
|
|
+<input type=file name=photo><input type=submit>
|
|
|
|
|
+</form><p>{{msg}}</p>"""
|
|
|
|
|
+
|
|
|
|
|
+def driver():
|
|
|
|
|
+ opts=Options()
|
|
|
|
|
+ opts.add_argument("--no-sandbox")
|
|
|
|
|
+ opts.add_argument("--disable-dev-shm-usage")
|
|
|
|
|
+ return webdriver.Remote(command_executor=SELENIUM_URL, options=opts)
|
|
|
|
|
+
|
|
|
|
|
+@app.route("/",methods=["GET","POST"])
|
|
|
|
|
+def index():
|
|
|
|
|
+ if request.method=="GET":
|
|
|
|
|
+ return render_template_string(HTML,msg="")
|
|
|
|
|
+ f=request.files.get("photo")
|
|
|
|
|
+ if not f: return render_template_string(HTML,msg="No file")
|
|
|
|
|
+ d=driver()
|
|
|
|
|
+ try:
|
|
|
|
|
+ d.get("https://www.vinted.pl")
|
|
|
|
|
+ time.sleep(3)
|
|
|
|
|
+ finally:
|
|
|
|
|
+ d.quit()
|
|
|
|
|
+ return render_template_string(HTML,msg="Demo executed")
|
|
|
|
|
+
|
|
|
|
|
+if __name__=="__main__":
|
|
|
|
|
+ app.run(host="0.0.0.0",port=5000)
|