使用python,我希望自动获取给定tweet的图像源(例如:tweet),以便在仪表板中显示它(图像)。如果你点击图片,你会看到tweet url + '/photo/1‘。然而,这不能下载。如果您右键单击图像(获取图像源)。您将获得一个指向图像url (https://pbs.twimg.com/media/D0t9bz)的链接,但是对于自动编码来说,这个链接是无法猜到的。关于如何自动下载或获取推文图源有什么建议吗?
发布于 2021-10-20 15:25:12
您拥有Tweet的ID,在本例中为1102112466283175936
您可以使用Twitter API来获取Tweet对象。图像信息在includes
数据中。
API查询是通过/2/tweets/:id
端点进行的,图像URL的路径为includes.media.url
。例如:
$ twurl -j "/2/tweets/1102112466283175936?media.fields=url&expansions=attachments.media_keys"
{
"data": {
"attachments": {
"media_keys": [
"3_1102112450588147712"
]
},
"id": "1102112466283175936",
"text": "5000 selfies make up this iconic image of @jeremycorbyn in today's @ObserverUK, calling on him to bring courage and leadership to unite @UKLabour MPs behind a #PublicVote on #Brexit. RT to support! [shortened link]"
},
"includes": {
"media": [
{
"media_key": "3_1102112450588147712",
"type": "photo",
"url": "https://pbs.twimg.com/media/D0t9bz_XgAAl3hD.jpg"
}
]
}
}
您可以使用Tweepy库从Python访问API。还可以使用其他API库。
https://stackoverflow.com/questions/69647927
复制相似问题