我想使用 Python3 BeautifulSoup 和请求模块从 https://mycurrentlocation.net/ 中提取纬度、经度和准确度

I want to extract the latitude, longitude and accurency from https://mycurrentlocation.net/ using Python3 BeautifulSoup and requests modules

我的基本想法是制作一个简单的脚本,以便使用此站点获取地理坐标:https://mycurrentlocation.net/。 当我 运行 我的脚本属性列为空并且程序没有正确 return 列表时:check the list 请帮我! :)

import requests,time

from bs4 import BeautifulSoup as bs

site="https://mycurrentlocation.net/"

def track_the_location():
    page=requests.get(site)
    page=bs(page.text,"html.parser")
    latitude=page.find_all("td",{"id":"latitude"})
    longitude=page.find_all("td",{"id":"longitude"})
    accuracy=page.find_all("td",{"id":"accuracy"})
    List=[latitude.text,longitude.text,accuracy.text]
    return List
print(track_the_location())

我认为问题在于您是 运行 来自本地脚本的事实。这与浏览器的行为不同,因为它不向网站提供任何位置信息。所需的信息是通过运行时提供的,因此您实际上需要模拟一个浏览器会话来获取数据,只要它们不提供 API,您可以在其中手动指定您的信息。

一个可能的解决方案是 selenium,因为它可以帮助您模拟浏览器会话。 Here's selenium 文档供进一步阅读。

希望能帮到你。祝你有个愉快的一天。