Q:

How does this code for extraction via string methods work?

I have read this code for extraction of data from a website through string methods:
def extract_results(data)
     start_index= data.find("<p>")
     while -1 != start_index:
         end_index = data.find("</p>", start_index)

Here what is while loop doing? Why start_index is being compared with -1?

A:

The return value of str.find() is -1 if the text is not found:

str.find(sub[, start[, end]])
  Return the lowest index in the string where substring sub is found, such that sub is contained in the slice s[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 if sub is not found.

The while loop effectively makes the code go into an endless loop if start_index is not -1 and is useless unless there is more code following the snippet you shared with us.
Presumably there is something like return data[start_index + 3:end_index] as a next line, in which case using if start_index > -1: instead of the while statement would have been far more readable.
It could be that start_index is set again further down, of course.

