Answer the question
In order to leave comments, you need to log in
I want to use Yandex Balaboba in a Python project, but how?
Tried several options.
import json
import urllib.request
headers = {
'Content-Type': 'application/json',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_4) AppleWebKit/605.1.15 '
'(KHTML, like Gecko) Version/14.1.1 Safari/605.1.15',
'Origin': 'https://yandex.ru',
'Referer': 'https://yandex.ru/',
}
API_URL = 'https://zeapi.yandex.net/lab/api/yalm/text3'
payload = {"query": "Ура Хабр", "intro": 0, "filter": 1}
params = json.dumps(payload).encode('utf8')
req = urllib.request.Request(API_URL, data=params, headers=headers)
response = urllib.request.urlopen(req)
print(response.read().decode('utf8'))
Answer the question
In order to leave comments, you need to log in
Yes, you are correct. Just need to decode the JSON.
import json
print( json.loads( response.read().decode('utf8') )["text"] )
# Вот и настал
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question