News Monitor Search =/= get_news_headlines()

Somehow I am not able to get the same results for News Monitor using the Python API. For example:

In News Monitor, my query is as follows:

R:PGA190 AND "summary" AND "regrade" AND "deals"

This returns relevant news records that match the search query.

image


However, in the Python API, I receive nothing in response to this query:

df = ek.get_news_headlines(query="R:PGA190 AND summary AND regrade AND deals")

I have also tried adding quote marks:

df = ek.get_news_headlines(query="R:PGA190 AND 'summary' AND 'regrade' AND 'deals'")


What might be my mistake here?

Best Answer

  • Hi @matthew.ang

    You can use this code:

    df = ek.get_news_headlines(query="R:PGA190 AND \\\"summary\\\" AND \\\"regrade\\\" AND \\\"deals\\\"")

    Here is the output:

    image


    Well, you have to pass "summary" to API call which expect a JSON input.

    So JSON-escaped text is \"summary\"

    Then

    \ escape charater in python is \\

    " escape charater is \"

    So \" becomes \\\" hence "summary" becomes \\\"summary\\\"

Answers