Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,5 @@
|
|
1 |
from selenium import webdriver
|
2 |
from selenium.webdriver.chrome.options import Options
|
3 |
-
from selenium.webdriver.common.by import By
|
4 |
-
from selenium.webdriver.support.ui import WebDriverWait
|
5 |
-
from selenium.webdriver.support import expected_conditions as EC
|
6 |
-
from selenium.common.exceptions import WebDriverException, TimeoutException
|
7 |
from fastapi import FastAPI, Request
|
8 |
import uvicorn
|
9 |
import time
|
@@ -11,49 +7,57 @@ 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 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
57 |
|
58 |
if __name__ == '__main__':
|
59 |
uvicorn.run(app='app:app', host="0.0.0.0", port=7860)
|
|
|
1 |
from selenium import webdriver
|
2 |
from selenium.webdriver.chrome.options import Options
|
|
|
|
|
|
|
|
|
3 |
from fastapi import FastAPI, Request
|
4 |
import uvicorn
|
5 |
import time
|
|
|
7 |
|
8 |
app = FastAPI()
|
9 |
|
10 |
+
def convert_cookies_to_dict(cookies):
|
11 |
+
cookies = dict([l.split("=", 1) for l in cookies.split("; ")])
|
12 |
+
return cookies
|
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, "user-agent": "New York"}'
|
19 |
+
mode = "get"
|
20 |
+
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"
|
21 |
+
|
22 |
+
header_array = json.loads(header_list)
|
23 |
+
cookies = convert_cookies_to_dict(cookies_string)
|
24 |
+
|
25 |
+
options = Options()
|
26 |
+
options.add_argument('--headless')
|
27 |
+
for key, value in header_array.items():
|
28 |
+
options.add_argument(f'{key}="{value}"')
|
29 |
+
|
30 |
+
driver = webdriver.Chrome(options=options)
|
31 |
+
# print(cookies)
|
32 |
+
# driver.add_cookie(cookies)
|
33 |
+
|
34 |
+
driver.get(target_url)
|
35 |
+
|
36 |
+
print(driver.page_source)
|
37 |
+
|
38 |
+
time.sleep(wait_time)
|
39 |
+
|
40 |
+
# 获取当前URL
|
41 |
+
current_url = driver.current_url
|
42 |
+
|
43 |
+
# 获取页面源代码
|
44 |
+
page_source = driver.page_source
|
45 |
+
|
46 |
+
# 获取cookie
|
47 |
+
cookies = driver.get_cookies()
|
48 |
+
|
49 |
+
# 是否有跳转过
|
50 |
+
is_jump = (target_url != current_url)
|
51 |
+
|
52 |
+
data = {
|
53 |
+
"url": current_url,
|
54 |
+
"page_source": page_source,
|
55 |
+
"cookies": cookies,
|
56 |
+
"is_jump": is_jump
|
57 |
+
}
|
58 |
+
|
59 |
+
driver.quit()
|
60 |
+
return {"code": 200,"data":data}
|
61 |
|
62 |
if __name__ == '__main__':
|
63 |
uvicorn.run(app='app:app', host="0.0.0.0", port=7860)
|