@3f4g

Как вытащить ссылку из массива данных в Python?

Подскажите пожалуйста как из следующего массива данных вытащить только адрес ссылки?:

[Message(id=899, peer_id=PeerUser(user_id=7415649360), date=datetime.datetime(2021, 8, 10, 9, 52, 37, tzinfo=datetime.timezone.utc), message='⚠️ WARNING: The following is a third party advertisement. Do not trust anything that promises to make you money. Use the following website at your own risk.\n---------------------  \n\nFree 100 OZC, price listing $30/OZC  \n\nStart in 15/07/2021: Free 100 OZC, price listing $30/OZC  \n  \n---------------------  \nPress the "Visit website" button to earn LTC.\nYou will be redirected to a third party site.', out=False, mentioned=False, media_unread=False, silent=False, post=False, from_scheduled=False, legacy=False, edit_hide=False, pinned=False, from_id=None, fwd_from=None, via_bot_id=None, reply_to=None, media=None, reply_markup=ReplyInlineMarkup(rows=[KeyboardButtonRow(buttons=[KeyboardButtonUrl(text=' Go to website', url='https://doge.click/visit/Ka1gfo')]), KeyboardButtonRow(buttons=[KeyboardButtonCallback(text=' Report', data=b'{"name":"ReportClick","id":"click_tasks61124bf44b4413.68559229"}', requires_password=False), KeyboardButtonCallback(text='⏩ Skip', data=b'{"name":"SkipClick","id":"click_tasks61124bf44b4413.68559229"}', requires_password=False)])]), entities=[MessageEntityItalic(offset=0, length=156), MessageEntityItalic(offset=157, length=21), MessageEntityBold(offset=182, length=35), MessageEntityItalic(offset=283, length=21), MessageEntityItalic(offset=307, length=45), MessageEntityItalic(offset=353, length=45)], views=None, forwards=None, replies=None, edit_date=None, post_author=None, grouped_id=None, restriction_reason=[], ttl_period=None), total=57]


В идеале с использованием библиотеки telethon или re. Это сообщение от бота в telegram, необходимо автоматизировать процесс перехода по ссылкам, (в обычном клиенте они в формате кнопок). Буду очень признателен за помощь.
  • Вопрос задан
  • 376 просмотров
Решения вопроса 1
SoreMix
@SoreMix Куратор тега Python
yellow
msg.reply_markup.rows[0].buttons[0].url

re:
import re

msg = '''[Message(id=899, peer_id=PeerUser(user_id=7415649360), date=datetime.datetime(2021, 8, 10, 9, 52, 37, tzinfo=datetime.timezone.utc), message='⚠️ WARNING: The following is a third party advertisement. Do not trust anything that promises to make you money. Use the following website at your own risk.\n---------------------  \n\nFree 100 OZC, price listing $30/OZC  \n\nStart in 15/07/2021: Free 100 OZC, price listing $30/OZC  \n  \n---------------------  \nPress the "Visit website" button to earn LTC.\nYou will be redirected to a third party site.', out=False, mentioned=False, media_unread=False, silent=False, post=False, from_scheduled=False, legacy=False, edit_hide=False, pinned=False, from_id=None, fwd_from=None, via_bot_id=None, reply_to=None, media=None, reply_markup=ReplyInlineMarkup(rows=[KeyboardButtonRow(buttons=[KeyboardButtonUrl(text=' Go to website', url='https://doge.click/visit/Ka1gfo')]), KeyboardButtonRow(buttons=[KeyboardButtonCallback(text=' Report', data=b'{"name":"ReportClick","id":"click_tasks61124bf44b4413.68559229"}', requires_password=False), KeyboardButtonCallback(text='⏩ Skip', data=b'{"name":"SkipClick","id":"click_tasks61124bf44b4413.68559229"}', requires_password=False)])]), entities=[MessageEntityItalic(offset=0, length=156), MessageEntityItalic(offset=157, length=21), MessageEntityBold(offset=182, length=35), MessageEntityItalic(offset=283, length=21), MessageEntityItalic(offset=307, length=45), MessageEntityItalic(offset=353, length=45)], views=None, forwards=None, replies=None, edit_date=None, post_author=None, grouped_id=None, restriction_reason=[], ttl_period=None), total=57]'''

print(re.search(r'(https://.+?)\'', msg).group(1))
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы