如何使用 selenium 和 json 文件中的坐标更改地理位置?

发布于 2025-01-11 08:28:13 字数 1393 浏览 0 评论 0原文

我正在尝试使用 selenium 和 json 文件中的坐标更改地理位置。但我使用的代码似乎不起作用,我不明白为什么。这是我使用的代码:

f = open("accounts.json",)
datas = json.load(f)

def project(data):
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.execute_cdp_cmd("Emulation.setGeolocationOverride", {
        "latitude": data["latitude"],
        "longitude": data["longitude"],
        "accuracy": 100
    })

    driver.get(data["email_link"])
for data in datas:
    tinder(data)

这是 json 文件的内容:

[
  {
      "latitude": "40.7142700",
      "longitude": "-74.0059700",
      "number": "8597108226",
      "number_link": "https://temp-number.com/inbox.php?country=United%20States&no=18597108226&in=US",
      "email_link": "https://emailfake.com/[email protected]",
      "full_email_link": "emailfake.com/[email protected]",
      "email_name": "[email protected]"
  }
]

错误发生在我的项目(数据)函数内的纬度和经度的两行中,如果我直接输入值而不是从 json 获取它们文件它有效。但使用 data["latitude"] 作为输入值不起作用。谁能帮我找出这里可能出现的错误吗?

I am trying to change geolocation with selenium with coordinates from a json file. But the code I use does not seem to work and I dont understand why. Here is the code I used:

f = open("accounts.json",)
datas = json.load(f)

def project(data):
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.execute_cdp_cmd("Emulation.setGeolocationOverride", {
        "latitude": data["latitude"],
        "longitude": data["longitude"],
        "accuracy": 100
    })

    driver.get(data["email_link"])
for data in datas:
    tinder(data)

and here is the content of the json file:

[
  {
      "latitude": "40.7142700",
      "longitude": "-74.0059700",
      "number": "8597108226",
      "number_link": "https://temp-number.com/inbox.php?country=United%20States&no=18597108226&in=US",
      "email_link": "https://emailfake.com/[email protected]",
      "full_email_link": "emailfake.com/[email protected]",
      "email_name": "[email protected]"
  }
]

The error occurs in the 2 lines for latitude and longitude inside my project(data) function, and if I input the values directly instead of getting them from the json file it works. but using the data["latitude"] as an input value does not work. Can anyone please help me figure out what the error here might be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有 2025-01-18 08:28:13

我知道无论如何回答都已经太晚了
试试这个

dates=[
  {
      "latitude": "40.7142700",
      "longitude": "-74.0059700",
      "number": "8597108226",
      "number_link": "https://temp-number.com/inbox.php?country=United%20States&no=18597108226&in=US",
      "email_link": "https://emailfake.com/[email protected]",
      "full_email_link": "emailfake.com/[email protected]",
      "email_name": "[email protected]"
  }
]
driver.execute_cdp_cmd("Emulation.setGeolocationOverride", {
        "latitude": dates[0]["latitude"],
        "longitude": dates[0]["longitude"],

I know it's to late for ansewer any way
try this

dates=[
  {
      "latitude": "40.7142700",
      "longitude": "-74.0059700",
      "number": "8597108226",
      "number_link": "https://temp-number.com/inbox.php?country=United%20States&no=18597108226&in=US",
      "email_link": "https://emailfake.com/[email protected]",
      "full_email_link": "emailfake.com/[email protected]",
      "email_name": "[email protected]"
  }
]
driver.execute_cdp_cmd("Emulation.setGeolocationOverride", {
        "latitude": dates[0]["latitude"],
        "longitude": dates[0]["longitude"],
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文