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