String.find is not returning any value
I am trying to substring the following value to get the link(image value) out of it:
<p>This is a recipe developed by my wife, Irene. It’s been tweaked to perfection. I've never ordered congee in Manila since then.</p>
<p style="text-align: center;">
(img src="http://img35.imageshack.us/img35/6047/69934653.jpg" alt="" >
</p>
I tried the following :
thumb = item.xpath('description')[0].text // To get the vaue from XML
pos = thumb.find('http') // Find http: and then Substring
Log('Position HTTP'+开发者_运维知识库pos)
thumb = thumb[:pos]
Log('Thumb Details'+thumb)
str.find()
returns int, so Log('Position HTTP'+pos)
will raise TypeError
.
Change to Log('Position HTTP %s' % pos)
Perhaps you should consider using the Regex module instead: http://docs.python.org/library/re.html
import re
match = re.search('http://\S+.(?:jpeg|jpg|png)', a_string)
print match.group(0)
精彩评论