How to search headlines with multiple keywords? Why is such an input wrong?

Best Answer

  • @yuyang
    "You typically don't need to use quotes around keywords. Try

    ek.get_news_headlines("Product:IFRFM AND Topic:ISU AND Topic:EUB AND (PRICED OR DEAL)")
    The above expression is syntactically correct, but returns an empty dataframe because the news search expression is too narrow and no headlines match it. Try instead for example:
    ek.get_news_headlines("Topic:ISU AND Topic:EUB AND (PRICED OR DEAL)")
    The reason your original news search expression results in an error is that Python library passes the news search expression string to a JSON object, which is then submitted in HTTP request to the Web service that delivers news headlines. This means that in order to escape a character you first need to escape it for Python and then for JSON. One way to do this is to use triple backslash:
    "Topic:ISU AND Topic:EUB AND (\\\"PRICED\\\" OR \\\"DEAL\\\")"
    Another is to use Python raw string:
    r"Topic:ISU AND Topic:EUB AND (\"PRICED\" OR \"DEAL\")"

    But as I said at the beginning the easiest is to not include keywords in quotes at all.

Answers