Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -16,45 +16,44 @@ 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 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
driver.get(target_url)
|
30 |
-
|
31 |
-
print(driver.page_source)
|
32 |
|
33 |
-
|
|
|
|
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
page_source = driver.page_source
|
40 |
-
|
41 |
-
# 获取cookie
|
42 |
-
cookies = driver.get_cookies()
|
43 |
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
58 |
|
59 |
if __name__ == '__main__':
|
60 |
uvicorn.run(app='app:app', host="0.0.0.0", port=7860)
|
|
|
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 |
|
21 |
+
|
22 |
+
options = Options()
|
23 |
+
options.add_argument('--headless')
|
24 |
+
driver = webdriver.Chrome(options=options)
|
25 |
|
26 |
+
header_array = json.loads(header_list)
|
27 |
+
for key, value in header_array.items():
|
28 |
+
driver.add_header(str(key), str(value))
|
|
|
|
|
|
|
|
|
29 |
|
30 |
+
driver.get(target_url)
|
31 |
+
|
32 |
+
print(driver.page_source)
|
33 |
|
34 |
+
time.sleep(wait_time)
|
35 |
+
|
36 |
+
# 获取当前URL
|
37 |
+
current_url = driver.current_url
|
|
|
|
|
|
|
|
|
38 |
|
39 |
+
# 获取页面源代码
|
40 |
+
page_source = driver.page_source
|
41 |
+
|
42 |
+
# 获取cookie
|
43 |
+
cookies = driver.get_cookies()
|
44 |
+
|
45 |
+
# 是否有跳转过
|
46 |
+
is_jump = (target_url != current_url)
|
47 |
+
|
48 |
+
data = {
|
49 |
+
"url": current_url,
|
50 |
+
"page_source": page_source,
|
51 |
+
"cookies": cookies,
|
52 |
+
"is_jump": is_jump
|
53 |
+
}
|
54 |
+
|
55 |
+
driver.quit()
|
56 |
+
return {"code": 200,"data":data}
|
57 |
|
58 |
if __name__ == '__main__':
|
59 |
uvicorn.run(app='app:app', host="0.0.0.0", port=7860)
|