Last Updated: February 25, 2016
· Mortezaipo

Fetch youtube links from HTML code

For fetching youtube links from HTML code , I have written a simple code with Python that can retrieve all links from HTML codes.

#!/usr/bin/env python
import re
pattern = '.*<(iframe|param).*(src|value)="(?P<link>|v)/[a-zA-Z0-9/\.\?&;=\+_-]+);?.*".*>.*</(iframe|param)>.*'
action = re.compile(pattern)
result = action.findall('<div><iframe.....></iframe><param......></param></div>')
print result

In my regex I have 2 types of tags , iframe or param. So if you have another one you can add that in the parenthesis like (mytag|iframe|param) and so on.

Be success.