我是新来的蟒蛇。有没有办法来简化这一点:我觉得我应该可以改为建立getDivs的匿名函数简化这个蟒蛇代
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())
。类似的信息(伪):
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)
]
感谢
使用'lxml'和'xpath':P应该为你提供一个oneliner ... – root 2013-05-09 13:27:19