3
3
3f4g2021-08-10 14:11:23
Python
3f4g, 2021-08-10 14:11:23

How to pull a reference from an array of data in Python?

Please tell me how to extract only the link address from the following data array?:

[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]


Ideally using the telethon or re library. This is a message from a bot in telegram, it is necessary to automate the process of following links (in a regular client they are in the format of buttons). I would be very grateful for help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-08-10
@3f4g

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))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question