Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,25 +11,33 @@ import json
|
|
| 11 |
|
| 12 |
app = FastAPI()
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
@app.get("/")
|
| 15 |
def main():
|
| 16 |
target_url = 'https://test5.container-z.art/test26'
|
| 17 |
wait_time = 10
|
| 18 |
-
header_list = '{"name": "John", "age": 30, "
|
| 19 |
mode = "get"
|
|
|
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
options = Options()
|
| 23 |
options.add_argument('--headless')
|
| 24 |
options.add_argument('--disable-gpu')
|
| 25 |
options.add_argument("no-sandbox")
|
| 26 |
options.add_argument("--disable-extensions")
|
|
|
|
|
|
|
| 27 |
|
| 28 |
driver = webdriver.Chrome(options=options)
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
driver.get(target_url)
|
| 34 |
|
| 35 |
print(driver.page_source)
|
|
|
|
| 11 |
|
| 12 |
app = FastAPI()
|
| 13 |
|
| 14 |
+
def convert_cookies_to_dict(cookies):
|
| 15 |
+
cookies = dict([l.split("=", 1) for l in cookies.split("; ")])
|
| 16 |
+
return cookies
|
| 17 |
+
|
| 18 |
@app.get("/")
|
| 19 |
def main():
|
| 20 |
target_url = 'https://test5.container-z.art/test26'
|
| 21 |
wait_time = 10
|
| 22 |
+
header_list = '{"name": "John", "age": 30, "user-agent": "New York"}'
|
| 23 |
mode = "get"
|
| 24 |
+
cookies_string = "_zap=386b2646-cd4f-48b0-831c-0f4e0fcb84d; d_c0=ATBVpddW2hePTs-uWJUqnuikOgCLTtzDaQ=|1702569488; _xsrf=9Exea3EejXTsAZewjRCns4TPklsjdCpV; __zse_ck=001_xCDDL0hUsjpAaMgmQE7pCfeU+zXi0/T+YTGbyY=OkkWy54lHQjmO1If3BOBMUzDjeY=d26WyAD5j0BG=m7jR7RrpRqv2ImjXDfJPzUEzARb4/TImweWRybZ5aGbVke4B; BEC=9f6899d2c0337126a73fd6e01ed7c740; gdxidpyhxdE=tfBS35OO12TxVYkb6i%5Ce7mQekmAMzv2e1Ah%5CGS4h%5CwU7xS47p9%2Fd4T%5CNEmx7s%2Bu%2Fr8mkLktUMVIPQ404Z1OxrejYyRQ3aSgLL7CBsT2nRhTXpzWaxqr7KyuaHSCMZjsK6OBaCM5GsMTSor4baQvmzWfo5SZqccCgWZTrn4Ii2tgDNH0w%3A1718799277544"
|
| 25 |
|
| 26 |
+
header_array = json.loads(header_list)
|
| 27 |
+
cookies = convert_cookies_to_dict(cookies_string)
|
| 28 |
+
|
| 29 |
options = Options()
|
| 30 |
options.add_argument('--headless')
|
| 31 |
options.add_argument('--disable-gpu')
|
| 32 |
options.add_argument("no-sandbox")
|
| 33 |
options.add_argument("--disable-extensions")
|
| 34 |
+
for key, value in header_array.items():
|
| 35 |
+
options.add_argument(f'{key}="{value}"')
|
| 36 |
|
| 37 |
driver = webdriver.Chrome(options=options)
|
| 38 |
|
| 39 |
+
driver.add_cookie(cookies)
|
| 40 |
+
|
|
|
|
| 41 |
driver.get(target_url)
|
| 42 |
|
| 43 |
print(driver.page_source)
|