69 lines
1.2 KiB
Python
69 lines
1.2 KiB
Python
import math
|
|
import copy
|
|
|
|
R = "0123456789ABCDEFGHIJKLMNOPQRSTUV"
|
|
|
|
|
|
def a(e: str) -> str:
|
|
t = int(e, 2)
|
|
return R[t]
|
|
|
|
|
|
def n(e: str) -> str:
|
|
t = ""
|
|
|
|
# 等价 charCodeAt + 16bit
|
|
for ch in e:
|
|
t += format(ord(ch), "016b")
|
|
|
|
# padEnd 到 5 的倍数
|
|
pad_len = 5 * math.ceil(len(t) / 5)
|
|
t = t.ljust(pad_len, "0")
|
|
|
|
r = ""
|
|
for i in range(0, len(t), 5):
|
|
r += a(t[i:i + 5])
|
|
|
|
return r
|
|
|
|
|
|
def generate_url(e: dict) -> str:
|
|
t = []
|
|
o = copy.deepcopy(e)
|
|
|
|
if o.get("jl"):
|
|
t.append(f"jl{o['jl']}")
|
|
del o["jl"]
|
|
|
|
if o.get("jt"):
|
|
t.append(f"jt{o['jt']}")
|
|
del o["jt"]
|
|
|
|
if o.get("in"):
|
|
t.append(f"in{o['in']}")
|
|
del o["in"]
|
|
|
|
if o.get("kw"):
|
|
t.append(f"kw{n(o['kw'])}")
|
|
del o["kw"]
|
|
|
|
if o.get("p"):
|
|
t.append(f"p{o['p']}")
|
|
del o["p"]
|
|
|
|
r = []
|
|
for key, value in o.items():
|
|
if value:
|
|
r.append(f"{key}={value}")
|
|
|
|
a_path = "/".join(t)
|
|
if r:
|
|
a_path += "?" + "&".join(r)
|
|
|
|
return a_path
|
|
|
|
|
|
if __name__ == '__main__':
|
|
url = f"https://www.zhaopin.com/sou/{generate_url({'jl': 530, 'kw': 'app推广经理'})}"
|
|
print(url)
|