【发布时间】:2020-08-11 14:26:44
【问题描述】:
在我的 python 项目中,我想获取我的 gps 位置。 所以我想解析一个网站,它给我这些信息: https://www.where-am-i.net/ 完美! 所以我写了以下脚本来解析纬度,经度:
from bs4 import BeautifulSoup
import requests
#website = "https://schlechtewitze.com/kurze-witze"
website = "https://www.where-am-i.net/"
source = requests.get(website).text
soup = BeautifulSoup(source, 'lxml')
for div in soup.find_all('div', class_ = "location"):
summary = div.p.text
print(summary)
print()
它几乎可以工作,但只是几乎:它返回:我的位置是:0.0, 0.0 如您所见,它返回的不是真实位置,因为我的计算机(Windows 10)阻止了位置请求。例如,当我在浏览器中打开它时:
只有在我点击允许(德语中的Zulassen)网站获取我的计算机位置后,才会显示该位置。
但是在脚本中我不能“点击这个按钮”。
问题结果: 如何让网站通过脚本获取我的位置(美汤,请求)?
(我不介意是否有其他解决方案(没有 bs4)来获取我的 GPS 位置)
【问题讨论】:
-
您需要发出与按钮相同的请求
-
我该怎么做呢?
-
你必须通过浏览器的开发者工具弄清楚请求是什么,然后用 python 复制
标签: python python-3.x beautifulsoup gps python-requests-html