Say I want the YouTube video ID from this link (VgC4b9K-gYU
):
https://www.youtube.com/watch?v=VgC4b9K-gYU
How would I get it using Python?
You need to use 'urlparse' library.
Python2
>>> import urlparse
>>> url = "https://www.youtube.com/watch?v=VgC4b9K-gYU"
>>> url_parsed = urlparse.urlsplit(url)
>>> qsl = urlparse.parse_qs(url_parsed.query)
>>> qsl
{'v': ['VgC4b9K-gYU']}
Python3
from urllib import parse
url = "https://www.youtube.com/watch?v=VgC4b9K-gYU"
url_parsed = parse.urlparse(url)
qsl = parse.parse_qs(url_parsed.query)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments