赞
踩
我在这里找到了一个Excel/VBA脚本,正在尝试将其转换为Python。首先是VBA,然后是Python。我应该如何修复Python代码?
Public Function GetUPSDeliveryDate(ByVal id As String) As String
Dim body As String, json As Object
body = "{""Locale"":""en_US"",""TrackingNumber"":[""" & id & """]}"
With CreateObject("MSXML2.XMLHTTP")
.Open "POST", "https://www.ups.com/track/api/Track/GetStatus?loc=en_US", False
.setRequestHeader "Referer", "https://www.ups.com/track?loc=en_US&requester=ST/"
.setRequestHeader "User-Agent", "Mozilla/5.0"
.setRequestHeader "DNT", "1"
.setRequestHeader "Content-Type", "application/json"
.setRequestHeader "Accept", "application/json, text/plain, */*"
.send body
Set json = JsonConverter.ParseJson(.responseText)
End With
我的尝试是:
def f(tn):
data = {"Locale":"en_US",
"TrackingNumber":f"[{tn}]",
"Referer": "https://www.ups.com/track?loc=en_US&requester=ST/",
"User-Agent": "Mozilla/5.0",
"DNT": "1",
"Content-Type": "application/json",
"Accept": "application/json, text/plain, */*"}
r = requests.post("https://www.ups.com/track/api/Track/GetStatus?loc=en_US", data=data)
print(r.json())
body
从VBA到
data
.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。