sumesh shetty
sumesh shetty

Reputation: 251

Requests library does not decode unicode characters via python code in specified url

I am trying to use requests library to get contents of url.

url:https://zee5transcoding-news-staging.s3.ap-south-1.amazonaws.com/RSS_Feed/rss_xml/rss_xml_2.xml

It opens in browser as following:

browser image

but when I use the python code to fetch this content using requests library the output is as follow: using request library

The python code is as follows:

import json
import requests

response = (requests.get("https://zee5transcoding-news-staging.s3.ap-south-1.amazonaws.com/RSS_Feed/rss_xml/rss_xml_2.xml" ).text)
print((response))

All the bengali language characters are somehow encoded i guess. Please help me to get the same content as I see in browser via python requets library.

Upvotes: 1

Views: 534

Answers (1)

Yash
Yash

Reputation: 1281

use .content instead of .text

import json
import requests

response = requests.get("https://zee5transcoding-news-staging.s3.ap-south-1.amazonaws.com/RSS_Feed/rss_xml/rss_xml_2.xml" ).content
with open("try.txt","a",encoding="utf8") as w:
    w.writelines((response).decode("utf8"))

Upvotes: 0

Related Questions