Добрый день!
Вот код:
import urllib.parse
import json
import requests
class TelegramMessage:
def __init__(self, searching_info, page):
self.searching_info = urllib.parse.quote(searching_info)
self.page = page
def write_in_file(self):
with open('telegram_msg.doc', 'w') as file:
for page in range(self.page):
try:
url = f'https://search.buzz.im/api/v1/search/messages_simple?query_text=' \
f'{self.searching_info}&query_size=100&query_from={page}'
r = requests.get(url)
messages = json.loads(r.text)['data']['messages']
channels_from_messages = [x['channel'] for x in messages]
[file.write('@' + items + ', ')
for items in channels_from_messages]
except KeyError as e:
print(e)
parsing = TelegramMessage(searching_info='ruby', page=10)
parsing.write_in_file()
Тот же код, который работает, но без класса:
searching_info = "привет"
searching_info = urllib.parse.quote(searching_info)
for i in range(0, 1):
url = 'https://search.buzz.im/api/v1/search/messages_simple?query_text=' + searching_info + '&query_size=100&query_from=' + str(i)
r = requests.get(url)
messages = json.loads(r.text)['data']['messages']
channels_from_messages = [x['channel'] for x in messages]
[print(x) for x in channels_from_messages]
Скажите, в чем проблема?
Спасибо заранее!