1

I have this code that I am trying to make asynchronous

def m1():
    links={
        #my list of links
    }
    rs = (grequests.get(u) for u in links)
    res = grequests.map(rs) 
    for r in res:
        z = 0
        soup = BeautifulSoup(r.text, 'lxml')
        soupstr = str(soup)
        if 'foo' in soupstr:
            list = []
            children = soup.find('div', class_='class')
            childrens = children.findChildren()
            for x in childrens:
                y = x.get('value')
                if y is None:
                    continue
                list.append(y)
            length = len(list)
            if length == 0:
                z = 0
            elif z < length:
                z = length
                #rest of the script

while True:
    m1()

But obviously that doesn't work because it makes z = 0 every loop. Any ideas?

casualpy
  • 11
  • 3
  • What is the *intended purpose of the code*? In particular, what is the intended purpose of `z`? – Karl Knechtel May 14 '20 at 17:19
  • I just want to check that an element is on the page one or more times, and then if it is it makes z = however many times that element is on the page. If its more than 1 I want it to do the rest of the script, if not I just want it to check again. – casualpy May 14 '20 at 17:22

0 Answers0