在我的 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)阻止了位置请求。例如,当我在浏览器中打开它时:
The location will only be shown after i clicked to allow (Zulassen in german) the website to get my computers location.
BUT in the script i can't "click this button".
Question Result: How can I allow the website to get my location via the script (beautiful soup, requests)?
(I would not mind if there is another solution (without bs4) to get my GPS location)
As MukundKulkarni mentioned there's this tutorial, which uses Selenium, to parse a website: How I Understood: Getting accurate current geolocation using Python Web-scraping and Selenium
Obviously they don't have to allow the location tracking first. I'll use Selenium for further web-scraping.
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句