python extract url from string code example
Example 1: extract url from page python
from bs4 import BeautifulSoup
your_html = '<div class="itemContainer"> <a c="" href="/mp3s/mp3/Shadmehr-Aghili-Avaz-Nemishi"><div class="image_crop"><img alt="2f370b436731d9b" src="'
sp = BeautifulSoup(your_html)
sp.find('a').get('href')
# output:
# /mp3s/mp3/Shadmehr-Aghili-Avaz-Nemishi
Example 2: how to separate url from text in python
(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w\.-]*)*\/?\S