-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch_keys.py
More file actions
39 lines (35 loc) · 1.46 KB
/
fetch_keys.py
File metadata and controls
39 lines (35 loc) · 1.46 KB
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
# Built-in modules
import threading, time
# Third-party modules
from playwright.sync_api import sync_playwright
def baidu_key ():
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":
key = page.evaluate ("SECKEY")
if len (key) > 50: # Key is longer than 50 characters
print ("Baidu: " + key)
return
time.sleep (0.1)
def tdt_key ():
with sync_playwright () as p:
browser = p.chromium.launch ()
page = browser.new_page ()
page.goto ("https://www.tianditu.gov.cn", wait_until = "domcontentloaded")
while True:
if page.evaluate ('typeof document.getElementsByClassName("leaflet-tile-loaded")[0]') != "undefined":
key = page.evaluate ('new URLSearchParams(document.getElementsByClassName("leaflet-tile-loaded")[0].src).get("tk")')
if len (key) == 32: # Key is 32 characters
print ("Tianditu: " + key)
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...")
tdt = threading.Thread (target = tdt_key)
tdt.start ()