当前位置:   article > 正文

python vba excel,将Excel/VBA转换为Python

vba封裝成python

我在这里找到了一个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

.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/661962
推荐阅读
相关标签
  

闽ICP备14008679号