Твиттер расширяет URL.Предположим, у вас есть один твит с использованием Twitter API, закодированный в виде файла json.
import json
urlInfo=[]
tweet=json.loads(tweet)
keyList=tweet.keys() # list of all posssible keys
tweet['entities'] # gives us values linked to entities
Вы можете заметить, что есть значение, называемое 'urls' tweet ['entity'] ['urls'] # дает значения, сопоставленные с ключевыми URL
urlInfo=tweet['entities']['expanded_url'] # move it to a list
# iterating over the list.. gives shortened URL
# and expanded URL
for item in urlInfo:
if "url" and "expanded_url" in urlInfo.keys():
print(item["url"] + " "+item["expanded_url"])