Python脚本不会重新启动/重试循环

时间:2017-06-16 12:59:31

标签: python loops selenium exception

我有一个带循环的Python脚本。 如果代码找不到指定的元素:(driver.find_element_by_xpath),他应该打印:“No Button”。然后他应该重启循环。

但是当我运行代码时,它将打印“No button”但是它继续脚本而不是重试/循环。

not_found=True
while not_found:

    try:
        browser=browser.open(link)
    except HTTPError, e:
        print 'The server couldn\'t fulfill the request.'
    except URLError, e:
        print 'Connection reset by peer'
        sys.stdout.write('\a')
        sys.stdout.flush()
        new=0
        time.sleep(5)


    search_k="just some text to look for"
    source="output.txt"

    if not search_string(search_k, source):
        print "this is a message reminder"       

        startstr='search text"'
        endstr='" />'
        file='output.txt'
        prijs=float(get_html_string(file,startstr,endstr))

        search_s="just some text in .txt"
        filez="blee.txt"
        search_z="texttt"
        search_q="texttttttt"

        if search_string(search_s, filez) and not search_string(search_z, filez) and not search_string(search_q, filez) and rule <= maxprijs:

            driver.get(link)
            try:
                elem = driver.find_element_by_xpath("//input[@type='submit' and @value='submit']")
                elem.click()
            except NoSuchElementException:
                print"No Button"              
                time.sleep(2)     
                new=0 #LOOP SCRIPT IGNORES?

0 个答案:

没有答案