1

我正在抓取电报,我可以在聊天中使用 client.iter_messages 获取每个消息实例,但如果消息实例是位置共享消息,我想获取该位置的纬度和经度。

for message in client.iter_messages('John'):
     print(message.text)   #prints message
     ------------------    #I want the latitude and longitude of the location if the message is a location share message and not a text message

一点帮助将不胜感激,谢谢。

4

1 回答 1

2

仅当消息是位置共享消息 ( message.geo) 时才执行,否则不需要

location = message.geo   #returns a GeoPoint class if the message is a location share message else returns None
if location is not None:
     longitude = location.long
     latitude = location.lat
     print(longitude, latitude)
于 2021-07-29T18:27:38.070 回答