0

我想做以下事情:

requestor = UrlRequestor("http://www.myurl.com/question?timestamp=", {'Content-Type': 'application/x-www-form-urlencoded', 'Cookie' : self.EASW_KEY + ";", 'X-UT-SID' :self.XUT_SID}, 'answer=' + self.securityHash)
requestor.open()
self.FUTPHISHING = requestor.getHeader('Set-Cookie').split(';')[0]

在时间戳之后,我想有这种格式的本地时间:1355002344943

我怎样才能做到这一点?

4

2 回答 2

1

You can get the time in that format from the time module. Specifically I'd do it this way

import time

timeurl = "http://www.myurl.com/question?timestamp=%s" % time.time()
requestor = UrlRequestor(timeurl, {'Content-Type': 'application/x-www-form-urlencoded',      'Cookie' : self.EASW_KEY + ";", 'X-UT-SID' :self.XUT_SID}, 'answer=' + self.securityHash)
requestor.open()
self.FUTPHISHING = requestor.getHeader('Set-Cookie').split(';')[0]

time.time() returns a float, so if it doesn't like that level of precision you can do

timeurl = "http://www.myurl.com/question?timestamp=%s" % int(time.time())
于 2012-12-08T22:01:36.803 回答
1

该时间戳看起来是基于Unix 时间(例如自 1970 年 1 月 1 日以来的秒数),但它还有三个数字。可能是毫秒,而不是秒。要复制它,我建议这样做:

import time

timestamp = int(time.time()*1000)
url = "http://www.myurl.com/question?timestamp=%d" % timestamp

如果您不想进行字符串格式化,也可以简单地将时间戳连接到 URL:

url = "http://www.myurl.com/question?timestamp=" + str(timestamp)
于 2012-12-08T22:13:34.790 回答