mardi 25 octobre 2016

Python IF statement inside FOR statement

So you can see below I have a simple FOR statement looping through a file, then inside that, I have an IF statement.

Everything works perfect as long as I have 1 entry in the txt file...

As soon as it has more than 1 entry in the file, and it runs though the for loop...it seems like it's ALWAYS returning the if statement results as true- which makes it always do a print '[!]Not Found'...

(using Mechanize library, and i can def confirm the response_string is the correct text for each entry- and the error_msg is correct as well)

It just seems to always choose the else in this structure...

import mechanize 

browser = mechanize.Browser()
browser.set_handle_equiv(True)
browser.set_handle_redirect(True)
browser.set_handle_referer(True)
browser.set_handle_robots(False)
browser.open('http://ift.tt/2dGEFLG')

for entry in thefile:
   browser.select_form(nr = 0)
   browser.form['hello-world'] = "testing"
   response = browser.submit()
   response_string = response.read()
   if error_msg in response_string:
      print '[!]Not Found'
   else:
      print '[!]Found'
      break;

Aucun commentaire:

Enregistrer un commentaire