Reputation: 1064
I have a string
str = <iframe width="420" height="315" src="https://www.youtube-nocookie.com/embed/jc8zayasOB8" frameborder="0" allowfullscreen></iframe>
and I want to take the substring in src - ie 'https://www.youtube-nocookie.com/embed/jc8zayasOB8'. So how can we achieve this. I tried this
my_string="hello python world , i'm a beginner "
print my_string.split("world",1)[1] .
But it gives all string after world . I want only the substring inside src.
Upvotes: 0
Views: 85
Reputation:
My solution:
string = '<iframe width="420" height="315" src="https://www.youtube-nocookie.com/embed/jc8zayasOB8" frameborder="0" allowfullscreen></iframe>'
start_src = string.find('src="')
first_quote = string.find('"', start_src)
end_quote = string.find('"', first_quote+1)
print string[first_quote+1:end_quote]
Upvotes: 1