lambda - simplify this python generation -
i new python. there way simplify this:
def getdivs(): divs = soup.findall(name = "div", attrs = {"class" : "resultcell"}, recursive = true) div in divs: h2 = div.find("h2") = h2.find("a") href = a["href"] yield (href) divs = list(getdivs())
i feel should able create anonymous function instead of getdivs. (pseudocode):
divs = [ divs = soup.findall(name = "div", attrs = {"class" : "resultcell"}, recursive = true) div in divs: h2 = div.find("h2") = h2.find("a") href = a["href"] yield (href) ]
thanks
just use list comprehension:
divs = [ div.find("h2").find("a")["href"] div in soup.findall(name = "div", attrs = {"class" : "resultcell"}, recursive = true) ]
but using proper xml parsing tools better idea.
Comments
Post a Comment