我是 python 新手。有没有办法简化这个:
def getDivs():
divs = soup.findAll(name = "div", attrs = {"class" : "resultCell"}, recursive = True)
for div in divs:
h2 = div.find("h2")
a = h2.find("a")
href = a["href"]
yield (href)
divs = list(getDivs())
我觉得我应该能够创建一个匿名函数而不是 getDivs。类似(伪代码):
divs =
[
divs = soup.findAll(name = "div", attrs = {"class" : "resultCell"}, recursive = True)
for div in divs:
h2 = div.find("h2")
a = h2.find("a")
href = a["href"]
yield (href)
]
谢谢