mercredi 26 décembre 2018

for loop Execution

I have two for loop. The outer loop reads from a text file and enters another for loop, which reads from a different text file when there is an exception. The inner loop should exit the loop and then iterate to the next element in the outer loop but again, once iterated it should continue from where it stopped in the inner loop.

Any idea as to how to do it in python?

following is the code:

with open('E:\marr.txt') as f:
    content = f.readlines()
content = [x.strip() for x in content]
with open('E:\prlist.txt') as f:
    content1 = f.readlines()
content1 = [x.strip() for x in content1]
with open('E:\Master\master1.csv', 'a') as f:
    headers = ("Source Link,Company Link,company name")
    f.write(headers)
    f.write("\n")
    for ip in content1:
        chrome_options.add_argument('--proxy-server=%s' % ip)
        try:
            for link in content:

                    try:
                        browser.get(link)
                        browser.implicitly_wait(4)
                        abba = browser.find_element_by_css_selector('.WebToolsetToolWebPart_Cntnr.WebToolsetToolWebPart_Aligned_LEFT.WebToolsetToolWebPart_TxtTool_Cntnr')
                        aas = abba.text
                        aa = aas.replace(",","")
                        print(ip + "," + link + "," + aa)
                        f.write(link + "," +aa+"\n")

                    except NoSuchElementException:
                        aa = "no count available"
                        print(ip + ","+link + "," + aa)
                        f.write(link + "," + aa + "\n")
        except StaleElementReferenceException:
            pass




Aucun commentaire:

Enregistrer un commentaire