开发者

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&rsquo;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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜