H
H
haoiwi2022-04-12 18:26:09
Python
haoiwi, 2022-04-12 18:26:09

Python,Telebot,URL?

How to make a user send a URL to a telegram bot and automatically extract the product id from it in bold? Like this:
https://www.amazon.com/Logitech-G502-Performance-G...
And the bot just retrieved the
Bot Product ID: Amazon - B07GBZ4Q68

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
Jack444, 2022-04-12
@haoiwi

def get_site_and_id(link: str) -> str:
    product_id = link.split('/', 6)[5]
    return f'Amazon - {product_id}'

K
Kadabrov, 2022-04-12
@Kadabrov

You can write a pattern using Regex
that will parse the url and get the right article,
as well as the option to split on a slash and get the next element after dp
split

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question