Answer the question
In order to leave comments, you need to log in
How to properly slice in a link?
ref_id = int(message.text[7:]) #получаем id
This is how I get the id from the link of the form:
https://t.me/test_bot?start=139513584
and I get an error at the output:
ValueError: invalid literal for int() with base 10: ''
Answer the question
In order to leave comments, you need to log in
Your message.text[7:] value is equal to "/t.me/test_bot?start=139513584" - how will Python assemble the int type from this?
What do you need to get as an output?
If you need a number at the end, and it is always of this length, then you need to use negative values in the slice
text=" https://t.me/test_bot?start=139513584 "
ref_id = int(text[-9:])
If you pull out what is after start is equal, suddenly there is a different length or letters in general, you can try split
text=" https://t.me/test_bot?start=139513584 "
text.split("?start=")
print (text.split( "?start=")[1])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question