Re: How to extract some text?
On Mar 8, 3:50 pm, Oltmans wrote: > On Mar 9, 3:37 am, Chris Rebert wrote: > > > Learn about the methods of the string class > > (str):http://docs.python.org/library/stdtypes.html#id4 > > > You'll probably be most interested in .split() > > OK, thanks I got it. I was trying to use Regex but .split() just > worked like a charm. Thank you ;) > > > > > Cheers, > > Chris > > > -- > > I have a blog:http://blog.rebertia.com > > The regex you were lookingfor was probably something like p = re.compile(r'href='(.*?)') when you p.match(mystring) group(1) will be your url -- http://mail.python.org/mailman/listinfo/python-list
Re: How to extract some text?
On Mar 9, 3:37 am, Chris Rebert wrote: > Learn about the methods of the string class > (str):http://docs.python.org/library/stdtypes.html#id4 > > You'll probably be most interested in .split() OK, thanks I got it. I was trying to use Regex but .split() just worked like a charm. Thank you ;) > > Cheers, > Chris > > -- > I have a blog:http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How to extract some text?
On Sun, Mar 8, 2009 at 5:18 PM, Oltmans wrote: > I'm at a loss to figure out how to extract some text from a string. > Here is a string: > > setTimeout("location.href='http://youtube.example.com/login.aspx'", > 5000); > > and I want to only retrieve the URL from above i.e I only want this > http://youtube.example.com/login.aspx from the above string. Any ideas/ > help is highly appreciated. > > Thanks, > Oltmans If x is your string: >>> pos = x.find("'") + 1 >>> x[pos:x.find("'", pos)] 'http://youtube.example.com/login.aspx' Find the first single quote, then get the character range between that and the next single quote. Tim -- http://mail.python.org/mailman/listinfo/python-list
Re: How to extract some text?
On Sun, Mar 8, 2009 at 2:18 PM, Oltmans wrote: > I'm at a loss to figure out how to extract some text from a string. > Here is a string: > > setTimeout("location.href='http://youtube.example.com/login.aspx'", > 5000); > > and I want to only retrieve the URL from above i.e I only want this > http://youtube.example.com/login.aspx from the above string. Any ideas/ > help is highly appreciated. Learn about the methods of the string class (str): http://docs.python.org/library/stdtypes.html#id4 You'll probably be most interested in .split() Cheers, Chris -- I have a blog: http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
How to extract some text?
I'm at a loss to figure out how to extract some text from a string. Here is a string: setTimeout("location.href='http://youtube.example.com/login.aspx'", 5000); and I want to only retrieve the URL from above i.e I only want this http://youtube.example.com/login.aspx from the above string. Any ideas/ help is highly appreciated. Thanks, Oltmans -- http://mail.python.org/mailman/listinfo/python-list