Container commited on
Commit
c712d59
·
verified ·
1 Parent(s): 5b38230

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -24
app.py CHANGED
@@ -14,35 +14,44 @@ app = FastAPI()
14
  def main():
15
  target_url = 'https://test5.container-z.art/test26'
16
  wait_time = 10
17
-
18
- options = Options()
19
- options.add_argument('--headless')
20
- driver = webdriver.Chrome(options=options)
21
- driver.get(target_url)
22
 
23
- time.sleep(wait_time)
 
 
24
 
25
- # 获取当前URL
26
- current_url = driver.current_url
27
-
28
- # 获取页面源代码
29
- page_source = driver.page_source
 
30
 
31
- # 获取cookie
32
- cookies = driver.get_cookies()
33
-
34
- # 是否有跳转过
35
- is_jump = (target_url != current_url)
36
 
37
- data = {
38
- "url": current_url,
39
- "page_source": page_source,
40
- "cookies": cookies,
41
- "is_jump": is_jump
42
- }
 
 
43
 
44
- driver.quit()
45
- return {"code": 200,"data":data}
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  if __name__ == '__main__':
48
  uvicorn.run(app='app:app', host="0.0.0.0", port=7860)
 
14
  def main():
15
  target_url = 'https://test5.container-z.art/test26'
16
  wait_time = 10
17
+ header_list = '{"name": "John", "age": 30, "User-Agent": "New York"}'
 
 
 
 
18
 
19
+ try:
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
+ time.sleep(wait_time)
 
 
 
 
31
 
32
+ # 获取当前URL
33
+ current_url = driver.current_url
34
+
35
+ # 获取页面源代码
36
+ page_source = driver.page_source
37
+
38
+ # 获取cookie
39
+ cookies = driver.get_cookies()
40
 
41
+ # 是否有跳转过
42
+ is_jump = (target_url != current_url)
43
+
44
+ data = {
45
+ "url": current_url,
46
+ "page_source": page_source,
47
+ "cookies": cookies,
48
+ "is_jump": is_jump
49
+ }
50
+
51
+ driver.quit()
52
+ return {"code": 200,"data":data}
53
+ except error:
54
+ return {"code": 500,"msg":error}
55
 
56
  if __name__ == '__main__':
57
  uvicorn.run(app='app:app', host="0.0.0.0", port=7860)