1

This is part of my python script:

   with open("/tmp/IpList.txt", "r+") as f:
    for ip in f:
        page = 1
        ip = ip.strip("\r\n")
        print ip
        while True:
            url = 'http://www.bing.com/search?q=ip%3a' + ip + '&qs=n&pq=ip%3a' + ip + '&sc=0-0&sp=-1&sk=&first=' + str(page) + '&FORM=PERE'
            print url
            with open("/tmp/content.txt", "a") as out:
                content = ContentFunc()
                if "<cite>" in content and "</cite>" in content:
                    out.write(content)
                    with open("/tmp/result.txt", "a+") as result:
                        res = CiteParser()
                        result.write(res.encode('utf-8'))
                    page += 10
                else:
                    break

I am going to handle my hosts from bing web site.

My break doesn't work here. when IPs are finished it goes and again reads first line of IpList.txt ... why?

MLSC
  • 5,872
  • 8
  • 55
  • 89
  • 1
    `result.close()` is unnecessary, as you use `with`, which automatically closes the file. – glglgl May 27 '14 at 12:04
  • 3
    That check does not do what you think it does, You compare if the string `""` is true (which is always the case) *and* if `""` is in content. – KillianDS May 27 '14 at 12:04
  • 4
    `if ""` is *always true*; the rest of that test is never executed. Boolean logic is not like English; you have to be explicit in your test. `if "" in content and "" in content:`. – Martijn Pieters May 27 '14 at 12:05
  • how can I correct it? could you possibly put answer ? – MLSC May 27 '14 at 12:07
  • No this is not always true..may be I put the IP wrong..so there is not and it should break from loop and goes to next line of IpList.txt – MLSC May 27 '14 at 12:10
  • @MortezaLSC nobody said the whole statement would be always true, it just won't do what you think it does. Aside from that, without knowing ContentFunc, CiteParser and your actual content we can't say much, you should post a minimal *reproducible* example. – KillianDS May 27 '14 at 12:25
  • Ok...`ContentFunc()` returns contents from bing pages. and `CiteParser()` returns hosts between `..` – MLSC May 27 '14 at 12:34
  • @ Martijn Pieters Thank you...but why my loop doesn't beak...there are no problem I thin in my code – MLSC May 27 '14 at 12:45

0 Answers0