Python regex

Questions about programming languages and debugging
Post Reply
User avatar
l0ngb1t
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 598
Joined: 15 Apr 2009, 16:00
15
Contact:

Python regex

Post by l0ngb1t »

hey am experimenting with python for the first time and am trying something
i need to extract the url from a line like this one:

Code: Select all

  <img class="photo2" src="http://www.blabla.com/bla/whatever" alt=""/>
it's done by regex i suppose, but how, any tut's on regex ? other the the doc's on python site
There is an UNEQUAL amount of good and bad in most things, the trick is to work out the ratio and act accordingly. "The Jester"

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Re: Python regex

Post by maboroshi »

I suggest looking into urlib2 and BeautifulSoup modules ;)

urlib to download the web page and BeautifulSoup to parse the HTML ;)

Maboroshi

User avatar
l0ngb1t
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 598
Joined: 15 Apr 2009, 16:00
15
Contact:

Re: Python regex

Post by l0ngb1t »

i used the urllib2 to get the source code
am looping through the lines to get the one that have the IMG tag and extract the image URL
it's the first time that i use python so...
how do i do it ?
i have read abt the beautiful soup but didn;t find something that extract the url :(
There is an UNEQUAL amount of good and bad in most things, the trick is to work out the ratio and act accordingly. "The Jester"

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Re: Python regex

Post by maboroshi »

A quick Google search reveals this, you will have to modify it to your situation

Code: Select all

http://stackoverflow.com/questions/499345/regular-expression-to-extract-url-from-an-html-link

User avatar
l0ngb1t
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 598
Joined: 15 Apr 2009, 16:00
15
Contact:

Re: Python regex

Post by l0ngb1t »

ok it worked well i guess
with both regex and beautiful soup
sorry for being so lazy to search more but am not having a good day and i need it done ASAP so...
again thankyou
There is an UNEQUAL amount of good and bad in most things, the trick is to work out the ratio and act accordingly. "The Jester"

Post Reply