Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.
I have a trouble with parsing a string for my use
OK, I have a string that I got from a website (when I'm not making the program it'll read it all the time...)
Here is the program:
--- START ---
# file = urllib2.urlopen("http://www.tremorseven.com/aim/deepaim.php?job=view
# print "URL Opened: " + file.geturl()
# URLInfo = file.read()
URLInfo = """Deep Thoughts by Jack Handey
#235: When this girl at the museum asked me whom I liked better, Monet or Manet, I said, "I like mayonnaise." She just stared at me, so I said it again, louder. Then she left. I guess she went to try to find some mayonnaise for me. Refresh
| add Deep Thoughts to your aimplease support this service.a service of tremorseven.com
print "Contents of URL: "
for x in range(0, len(URLInfo)):
if (URLInfo[x] == '#'):
for y in range(x, x + 5):
if (URLInfo[y] == ':'):
NumberStr = URLInfo[x+1:y]
print "Number of Deep Thought: " + NumberStr
StartOfThought = y+2
for z in range(StartOfThoughts, len(URLInfo)):
if (URLInfo[z] == '<':
EndOfThought = z
print "Contents of Deep Thought:"
print URLInfo[StartOfThought: EndOfThought]
---- END ----
I search for the # (this works), then i search for the ":" (this works) and i retrieve the number of this deep thought. Then i search for the position after the ":" for a "<" (this doesn't work).
And it does not work (dum dum dum). Any help would be appreciated.
0 · ·