If I am more familiar with html, I will probably consider one of the suggested libraries. But now I have solved this:
startImgPos = post.find('<img', 0, len(post)) + 4
if(startImgPos > -1):
endImgPos = post.find('>', startImgPos, len(post))
imageTag = post[startImgPos:endImgPos]
startSrcPos = imageTag.find('src="', 0, len(post)) +5
endSrcPos = imageTag.find('"', startSrcPos , len(post))
linkTag = imageTag[startSrcPos:endSrcPos]
r['linktag'] = linkTag
I will improve this later, but at the moment it does the trick. Feel free to suggest more ideas / improvements for the above code.
source
share