File size: 2,046 Bytes
494cdcf
 
973d2bc
 
ca11d6d
baf3cbb
e37298f
973d2bc
e37298f
8996078
 
 
 
973d2bc
 
5b38230
 
ae1fc9f
8996078
 
 
 
 
 
 
 
142e302
 
8996078
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e37298f
973d2bc
 
 
e37298f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
59
60
61
62
63
64
65
66
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from fastapi import FastAPI, Request
import uvicorn
import time
import json

app = FastAPI()

def convert_cookies_to_dict(cookies):
    cookies = dict([l.split("=", 1) for l in cookies.split("; ")])
    return cookies
    
@app.get("/")
def main():
    target_url = 'https://test5.container-z.art/test26'
    wait_time = 10
    header_list = '{"user-agent": "New York"}'
    mode = "get"
    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"

    header_array = json.loads(header_list)
    cookies = convert_cookies_to_dict(cookies_string)
    
    options = Options()
    options.add_argument('--headless')
    # for key, value in header_array.items():
    #     options.add_argument(f'{key}="{value}"')
    
    driver = webdriver.Chrome(options=options)
    # print(cookies)
    # driver.add_cookie(cookies)
    
    driver.get(target_url)

    print(driver.page_source)
    
    time.sleep(wait_time)

    # 获取当前URL
    current_url = driver.current_url
    
    # 获取页面源代码
    page_source = driver.page_source
    
    # 获取cookie
    cookies = driver.get_cookies()

    # 是否有跳转过
    is_jump = (target_url != current_url)
    
    data = {
        "url": current_url,
        "page_source": page_source,
        "cookies": cookies,
        "is_jump": is_jump
    }
    
    driver.quit()
    return {"code": 200,"data":data}

if __name__ == '__main__':
    uvicorn.run(app='app:app', host="0.0.0.0", port=7860)