【发布时间】:2017-06-28 01:30:28
【问题描述】:
我正在尝试从特定国家/地区获取推文。我正在使用 tweepy api 来获取推文。这是我到目前为止的代码 -
api = tweepy.API(auth)
places = api.geo_search(query="India", granularity="country")
place_id = places[0].id
public_tweets = api.search(q="place:%s" % place_id)
for one in public_tweets:
print(one.place)
这是我为上述代码 sn-p 得到的结果 -
None
None
Place(_api=<tweepy.api.API object at 0x1033f7690>, country_code=u'IN', url=u'https://api.twitter.com/1.1/geo/id/243cc16f6417a167.json', country=u'India', place_type=u'city', bounding_box=BoundingBox(_api=<tweepy.api.API object at 0x1033f7690>, type=u'Polygon', coordinates=[[[78.3897718, 17.3013989], [78.5404168, 17.3013989], [78.5404168, 17.4759], [78.3897718, 17.4759]]]), contained_within=[], full_name=u'Hyderabad, Andhra Pradesh', attributes={}, id=u'243cc16f6417a167', name=u'Hyderabad')
Place(_api=<tweepy.api.API object at 0x1033f7690>, country_code=u'IN', url=u'https://api.twitter.com/1.1/geo/id/1b8680cd52a711cb.json', country=u'India', place_type=u'city', bounding_box=BoundingBox(_api=<tweepy.api.API object at 0x1033f7690>, type=u'Polygon', coordinates=[[[77.3734736, 12.9190365], [77.7393706, 12.9190365], [77.7393706, 13.2313813], [77.3734736, 13.2313813]]]), contained_within=[], full_name=u'Bengaluru, Karnataka', attributes={}, id=u'1b8680cd52a711cb', name=u'Bengaluru')
None
None
None
None
None
None
Place(_api=<tweepy.api.API object at 0x1033f7690>, country_code=u'IN', url=u'https://api.twitter.com/1.1/geo/id/1dc2b546652c55dd.json', country=u'India', place_type=u'admin', bounding_box=BoundingBox(_api=<tweepy.api.API object at 0x1033f7690>, type=u'Polygon', coordinates=[[[73.8853747, 29.5438816], [76.9441213, 29.5438816], [76.9441213, 32.5763957], [73.8853747, 32.5763957]]]), contained_within=[], full_name=u'Punjab, India', attributes={}, id=u'1dc2b546652c55dd', name=u'Punjab')
Place(_api=<tweepy.api.API object at 0x1033f7690>, country_code=u'IN', url=u'https://api.twitter.com/1.1/geo/id/1dc2b546652c55dd.json', country=u'India', place_type=u'admin', bounding_box=BoundingBox(_api=<tweepy.api.API object at 0x1033f7690>, type=u'Polygon', coordinates=[[[73.8853747, 29.5438816], [76.9441213, 29.5438816], [76.9441213, 32.5763957], [73.8853747, 32.5763957]]]), contained_within=[], full_name=u'Punjab, India', attributes={}, id=u'1dc2b546652c55dd', name=u'Punjab')
None
None
Place(_api=<tweepy.api.API object at 0x1033f7690>, country_code=u'IN', url=u'https://api.twitter.com/1.1/geo/id/1b8680cd52a711cb.json', country=u'India', place_type=u'city', bounding_box=BoundingBox(_api=<tweepy.api.API object at 0x1033f7690>, type=u'Polygon', coordinates=[[[77.3734736, 12.9190365], [77.7393706, 12.9190365], [77.7393706, 13.2313813], [77.3734736, 13.2313813]]]), contained_within=[], full_name=u'Bengaluru, Karnataka', attributes={}, id=u'1b8680cd52a711cb', name=u'Bengaluru')
大多数推文没有地理标记。如何确保结果中只显示带有地理标记的推文?
【问题讨论】: