Skylight Skylight - 4 years ago 74
HTML Question

how to print everything after keyword ? for instance print everything between word "Apple" and word "Pen"

I need to make a script what showing me all the characters in between the keywords.

Let's say, I download html page and then read it (it has 33985 characters in there). I need to print everything between

"<td class="ml_subject"><a href="?tab=inbox"
and
"</a></td>"
which is dozen letters away.

I can find the start point by using:

if "<td class="ml_subject"><a href="?tab=inbox" in html:
print "Success"


but what's then ?

Answer Source

Use the find() method: -> http://docs.python.org/library/stdtypes.html#str.find

This would look something like this:

# html is your input string
start = html.find( '<td class="ml_subject"><a href="?tab=inbox>' )
end = html.find( '</a></td>', start )
result = html[start:end]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download