如何在python中制作HTML5 Geolocation对象

How to make a HTML5 Geolocation object in python?

本文关键字:HTML5 Geolocation 对象 python      更新时间:2023-09-26

我正在测试一些软件分析,我需要发送带有具有可变时间戳和位置的地理位置对象的GET请求。该网站使用 HTML5 navigator.getcurrent.location()。

我可以使用随机模块来随机化位置和时间戳。但是,JSON 对象创建部分让我感到困扰,因为文档中的结构具有空值,而 python 字典不接受它。

那么,你能告诉我如何在python中创建一个HTML5地理位置对象,该对象已准备好通过GET请求发送?

我假设你正在使用 eval 来解析你的 JSON,因为你说 python 不接受 null 关键字。在JSON上使用eval在任何语言中都是自找麻烦的。Python有一个内置的JSON解析器。用它!

import json
# put GET response in location_json_string
location_dict = json.loads(location_json_string)

要编码:

# Put your data in data_dictionary
request_json = json.dumps(data_dictionary)
# send GET request appending request_json to the URL