0

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.

1 Answer 1

1

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]
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot dear friend

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.