Adding story text to output using Python API

Hi
I currently have the following code that is fetching specific new articles using Python API. However I am not sure how to add the story text to the output. I currently have the Headline, StoryId, and Link to the article.
Code:
df = ek.get_news_headlines(
'Topic:GB AND (SOURCE:CMPNY OR SOURCE:MCE OR SOURCE:GEN)',
date_from='2025-07-23',
date_to='2025-07-30')
df
df['Links']=""
for idx, story in enumerate(df['storyId']):
soup = BeautifulSoup(ek.get_news_story(story))
links=[]
for a in soup.find_all('a', href=True):
links.append(a['href'])
df['Links'][idx] = links
df
I've added the output as a picture.
Any help would be great. Thanks.
Answers
-
Thank you for reaching out to us.
The code could be like this:
df = ld.news.get_headlines( 'Topic:GB AND (SOURCE:CMPNY OR SOURCE:MCE OR SOURCE:GEN)', start='2025-07-23', end='2025-07-29') df['Links']="" df['Story']="" for idx, story in enumerate(df['storyId']): story_text = ld.news.get_story(story, format=ld.news.Format.TEXT) soup = BeautifulSoup(ld.news.get_story(story, format=ld.news.Format.HTML)) links=[] for a in soup.find_all('a', href=True): links.append(a['href']) df['Links'][idx] = links df['Story'][idx] = story_text df
I use the LSEG Data Library for Python.
The news example is on GitHub.
0 -
Hello @s.tank
This
might help you upgrade from the Eikon Data API to the Data Library.0 -
Hi Jirapongse
I had tried this before using ld.news.get_story but it keeps running into issues. I have attached the error message I receive. Below are the list of my imports I have before any code.
import re
import pandas as pd
from bs4 import BeautifulSoup
import requests
import bs4
import html5lib
import eikon as ek
import numpy as np
import configparser as cp
import lseg.data as ld
import shutil
import openpyxl
from openpyxl import load_workbook
from openpyxl.utils.dataframe import dataframe_to_rows
import pyodbc
import sqlite3
import html2text
from IPython.display import HTML
from IPython import get_ipython
cfg = cp.ConfigParser()
cfg.read('eikon.cfg')
ek.set_app_key('***')ld.open_session()
I've added *** instead of my appkey here.
Am I missing an import? Thanks
0 -
Hi Wasin.
Thanks for the link, I had gone through these links beforehand but was running into the error I mentioned in my response to Jirapongse. Thanks for the help.
0 -
Hello @s.tank
You cannot set the app-key to Data library via ek.set_app_key() method. They are different library and not share session among each other.
To use a Data Library with the Desktop session, there are two ways.
Programmatic Way
You can set the app-key in the ld.open_session() method directly.
import lseg.data as ld APP_KEY = 'Your App-Key' ld.open_session(app_key = APP_KEY)
You can see more example on GitHub: Session example.
Configuration file
Create a file name lseg-data.config.json in the same location as your application (Python code or Notebook file).
{
"logs": {
"level": "debug",
"transports": {
"console": {
"enabled": false
},
"file": {
"enabled": false,
"name": "lseg-data-lib.log"
}
}
},
"sessions": {
"default": "desktop.workspace",
"desktop": {
"workspace": {
"app-key": "Your App-Key"
}
}
}
}Then, just use the ld.open_session() method to initialize the session
import lseg.data as ld ld.open_session()
0 -
Hi Wasim, thats for the app key information It is working now. I've edited the code so that it also searched the story text for a key word (drop). Below is my code.
df = ld.content.news.headlines.Definition(
query="Topic:GB AND (SOURCE:CMPNY OR SOURCE:MCE OR SOURCE:GEN) AND drop", extended_params={"searchIn": "FullStory"}
).get_data()
df.data.dfI have attached the output. Do you know why this isn't working and showing more results?
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 37 Alpha
- 167 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 702 Datastream
- 1.5K DSS
- 633 Eikon COM
- 5.2K Eikon Data APIs
- 14 Electronic Trading
- 1 Generic FIX
- 7 Local Bank Node API
- 6 Trading API
- 2.9K Elektron
- 1.5K EMA
- 257 ETA
- 566 WebSocket API
- 40 FX Venues
- 16 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 25 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 283 Open PermID
- 47 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 24 RDMS
- 2.1K Refinitiv Data Platform
- 823 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 122 Open DACS
- 1.1K RFA
- 107 UPA
- 195 TREP Infrastructure
- 232 TRKD
- 918 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 100 Workspace SDK
- 11 Element Framework
- 5 Grid
- 19 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛