-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch_keys.py
37 lines (32 loc) · 1.13 KB
/
fetch_keys.py
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
# Built-in modules
import time
# Third-party modules
from playwright.sync_api import sync_playwright
import threading
keys = {}
def baidu_key ():
global keys
with sync_playwright () as p:
browser = p.chromium.launch ()
page = browser.new_page ()
page.goto ("https://maps.baidu.com", wait_until = "domcontentloaded")
while True:
if page.evaluate ("typeof SECKEY") != "undefined":
keys ["baidu"] = page.evaluate ("SECKEY")
if len (keys ["baidu"]) > 50: # Key is longer than 50 characters
return
time.sleep (0.1)
with sync_playwright () as p:
print ("Starting Baidu thread...")
baidu = threading.Thread (target = baidu_key)
baidu.start ()
print ("Starting Tianditu thread...")
browser = p.chromium.launch ()
page = browser.new_page ()
page.goto ("https://www.tianditu.gov.cn/")
keys ["tdt"] = page.evaluate ("TDT_CONFIG['maptoken']")
print ("Tianditu thread finished.")
baidu.join ()
print ("Baidu thread finished.")
browser.close()
print (f"Baidu: {keys ['baidu']}\nTianditu: {keys ['tdt']}")