I am trying to convert my embed tweet html to a picture. modules :
import tweepy as tw
import imgkit
this is how i get embed tweets using tweepy:
def get_embed():
# ----------------------------------- Twitter API
consumer_key = "consumer_key"
consumer_secret = "consumer_secret"
access_token = "access_token"
access_token_secret = "access_token_secret"
# ------------------ Activating Tweepy session
auth = tw.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
tw_api = tw.API(auth)
url = "https://twitter.com/DisneyPlusNL/status/1427605982524461082?s=20"
result = tw_api.get_oembed(url, theme="dark")
return result['html']
and this is how I'm trying to convert it to a picture:
def cnv2image(html):
imgkit.from_string(html, 'imagekit.png')
cnv2image(get_embed())
but the result isn't how it should be.
expected result : https://drive.google.com/file/d/1C3Cny8hpbL4MfKH2sxynBhsDM9WsnNts/view?usp=sharing
result : https://drive.google.com/file/d/1NZZykQ1fuzvf9zRLkCVl6wTcGPCa5cgE/view?usp=sharing
You don't even need
tweepy
orimgkit
to do this, nor do you need someone else's API, just useselenium
:This code will create an image file called
tweet.png
that looks like:You can install
selenium
viapip install selenium
. This code uses Firefox, but you can configure it to use Chrome as well, and you'll get the exact same output. There's plenty of resources online on how to fully configure it.