question

Upvotes
Accepted
11 3 3 3

HTML to TEXT style (News story)

Hi

I would like to get news in text in Jupyter Notebook.

But I can get news only in HTML.

How can I get text style news story?

headlines = ek.get_news_headlines('IBM') for index, headline_row in headlines.iterrows(): story=ek.get_news_story(headline_row['storyId'])

print (story, content-Type: text/html)

eikoneikon-data-apipythonworkspacerefinitiv-dataplatform-eikonworkspace-data-apinewshtml
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvote
Accepted
86.2k 292 53 78

With Jupyter Notebook, you can use HTML() to display it as HTML.

from IPython.display import HTML
...

headlines = ek.get_news_headlines('IBM') 
for index, headline_row in headlines.iterrows(): story=ek.get_news_story(headline_row['storyId'])

HTML(story)


html.png (39.7 KiB)
text.png (42.6 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
4.3k 2 4 5

A Python library is available for this : https://pypi.python.org/pypi/html2text

There is more info here : https://github.com/Alir3z4/html2text/blob/master/docs/usage.md

Simple example with options:

import html2text
...
text_maker = html2text.HTML2Text()
text_maker.ignore_links = True
text_maker.bypass_tables = False
html_story = ek.get_news_story(headline_row['storyId'])
text_story = = text_maker.handle(html_story)
print(text_story)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
11 3 3 3

I could get text based news. Thank you guys for your support.

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.