How to get the image file with imageId?

Hi,

I ended up having the news 'imageId' but i don't know how to get the image by using 'imageId'


here is the code :


top_news = rd.content.news.top_news.hierarchy.Definition().get_data();

front_page = rd.content.news.top_news.Definition(top_news.data.df["topNewsId"][0]).get_data()

daf = front_page.data.df

for i in range(len(daf)):

print(daf.headline[i])

print(daf.storyId[i])

print(daf.imageId[i])


but when i get the contents by using 'storyId', The image file is not included in html..

Best Answer

  • @jwlee08

    Please try the code below.

    from refinitiv.data.content import news

    top_news = news.top_news.hierarchy.Definition().get_data();
    #Front Page News
    front_page = news.top_news.Definition(top_news.data.df["topNewsId"][0]).get_data()
    front_page.data.df

    1702538587308.png

    Then, get an image.

    definition = news.images.Definition(front_page.data.df["imageId"][0])
    response = definition.get_data()
    image = response.data.image
    image.show()

Answers

  • Hi,

    1702856830588.png

    I tried the same way.

    but I can't see images..

    and there is no show() function in 'response.data.image'

    1702856921787.png

    these are all i have.

    what should i try?

  • @jwlee08

    I think it depends on the tool that you are using. The show method works fine on Jupyter Notebook.

    1702875007591.png

    You may need to use other methods, such as save. Please run the help(image) statement.

  • Thank you. That helps alot!