Python'ning re moduli orqali matndan ma'lum shart asosida, matnning kerakli bo'lagini qirqib olish usulini - mover.uz'dagi video misolida ko'ramiz! Uni quyidagi funksiya orqali olish mumkin:
>>> url = 'https://mover.uz/watch/I2V2OKE/'
>>> import re
>>>
>>>
>>> def mover_video_url_getter(url):
... try:
... groups = re.search('https://mover.uz/watch/(.+?)/', url).groups()
... except Exception as e:
... print("Havola noto'g'ri berilgan")
... return
... else:
... if len(groups) > 0:
... video_name = groups[0]
... video_url = "https://v.mover.uz/{}_m.mp4".format(video_name)
... return video_url
... else:
... print('Mos havola topilmadi')
... return
...
>>> mover_video_url_getter(url)
'https://v.mover.uz/I2V2OKE_m.mp4'
Funksiyaning vazifasi: mover.uz'dagi biror videoga havolani berganda, funksiya video fayl turgan havolani qaytaradi.
@uzpythonlogs
#parsing #regex #videohavola
>>> url = 'https://mover.uz/watch/I2V2OKE/'
>>> import re
>>>
>>>
>>> def mover_video_url_getter(url):
... try:
... groups = re.search('https://mover.uz/watch/(.+?)/', url).groups()
... except Exception as e:
... print("Havola noto'g'ri berilgan")
... return
... else:
... if len(groups) > 0:
... video_name = groups[0]
... video_url = "https://v.mover.uz/{}_m.mp4".format(video_name)
... return video_url
... else:
... print('Mos havola topilmadi')
... return
...
>>> mover_video_url_getter(url)
'https://v.mover.uz/I2V2OKE_m.mp4'
Funksiyaning vazifasi: mover.uz'dagi biror videoga havolani berganda, funksiya video fayl turgan havolani qaytaradi.
@uzpythonlogs
#parsing #regex #videohavola