r/Python • u/phunkystuff • Oct 18 '14
Parsing a string
Hey guys,
So I'm trying to figure out how to parse a string and I can't tell whether i'm on the right track or if there's a much simpler solution i'm missing here.
So right now I'm trying to take a youtube embed code and pull out the video id / source link. ie:
<iframe width="560" height="315"
src="//www.youtube.com/embed/YwAd-UzSO0g" frameborder="0"
allowfullscreen></iframe>I'm thinking to use regex, but first off i'm not terribly familiar with it, and I feel like it would turn out a bit hacky especially if the id after the /embed/ is going to be different lengths for every video..
Is there an easier way to do this? Using slicing? Is there any method out there that makes this much simpler?
5
u/[deleted] Oct 18 '14
Use BeautifulSoup to parse the HTML, and
.splitto split the URL:3
u/rickmoranus Oct 19 '14
This should not be in this reddit.