EIKON API: News headline and story

Currently, I'm using the coding to retrieve the story below. I'd like to add the headline of the news. How can I do it?

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

articledata=""


headlines = ek.get_news_headlines(query='JPXエネルギー',count=1)

story = headlines.iat[0,2]

data_all=ek.get_news_story(story)


maru_count_list = []

for m in re.finditer('。', data_all):

maru_count_list.append(m.end())


html_story = data_all[0:maru_count_list[1]]


soup = BeautifulSoup(html_story, 'html.parser')

articledata = [i.get_text() for i in soup.select('p')]

print(headlines)

print(articledata)

# type(articledata)


articledata

Best Answer

  • headlines = ek.get_news_headlines(query='JPXエネルギー',count=1)
    headlineText = headlines.iat[0,1]
    print(headlineText)

    storyID = headlines.iat[0,2]
    print(storyID)

    storyText = ek.get_news_story(storyID)
    print(storyText)


    import csv
    output_file = open('output_file.csv', mode='w',encoding="utf-8")
    output_writer = csv.writer(output_file)

    output_writer.writerow(['StoryID','HeadlineText','StoryText'])
    output_writer.writerow([storyID, headlineText, storyText])

    output_file.close()


    You can use the code to get story, story id and headline.