question

DanielTroyer-2675 avatar image
0 Votes"
DanielTroyer-2675 asked YutongTie-MSFT commented

Bing Search API "&#39" appending to response

I am using the Bing Search API and this string of characters "&#39" is being appended to the name and description, is this simply because i am only using a Free Trial version or is the json not being parsed properly?

 `search_url = "https://api.bing.microsoft.com/v7.0/news/search"
 headers = {"Ocp-Apim-Subscription-Key" : subscription_key}
 params  = {"q": search_term, "textDecorations": False, "textFormat": "HTML"}
 response = requests.get(search_url, headers=headers, params=params)
 response.raise_for_status()
 response_dict = response.json()`

'name': 'What Is Filecoin and Why Is the Cryptocurrency's Price Going Up?',


azure-bing-news
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DanielTroyer-2675 avatar image
0 Votes"
DanielTroyer-2675 answered YutongTie-MSFT commented
  1. List item

Thank you for you response to my question, I am a beginner, I found my problem was not with the API or with Json parsing, but It was Django rendering the HTML, I fixed the problem by adding

 {% autoescape on %}  
 { name | safe }}  
 { description | safe }}  
 {% endautoescape %}  


· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Great! Hope you can accept your answer to help the community.


Regards,
Yutong

0 Votes 0 ·
YutongTie-MSFT avatar image
0 Votes"
YutongTie-MSFT answered

Hello,

I just tried in my end and I can receive the right result with/without the "hypertext". But from my testing, "&#39" can not be translated correct to ('). You can use (') directly. Two things may help:

  1. The result shows only descriptions in the sample code

  2. You could set up the language with mkt = "en-US" in params

I am sharing my JSON result for your reference:

84672-image.png

And also my code:

 import json
 import os
 import requests
    
 subscription_key = "****************************"
 assert subscription_key
    
 search_url = "https://api.bing.microsoft.com/v7.0/news/search"
 search_term = "What Is Filecoin and Why Is the Cryptocurrency's Price Going Up?"
    
 mkt = 'en-US'
 headers = {"Ocp-Apim-Subscription-Key" : subscription_key}
 params  = {"q": search_term, "textDecorations": True, "textFormat": "HTML", 'mkt': mkt}
 response = requests.get(search_url, headers=headers, params=params)
 response.raise_for_status()
 search_results = response.json()
    
 descriptions = [article["description"] for article in search_results["value"]]
 print(response.json())
    
 from IPython.display import HTML
 rows = "\n".join(["<tr><td>{0}</td></tr>".format(desc) for desc in descriptions])
 HTML("<table>"+rows+"</table>")



Please let me know if you have any question.

Regards,
Yutong


image.png (201.9 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.