列表推导式实现:
for webElement in webElements: fields = webElement.find_elements_by_css_selector('span') resultlist = [field.text for field in fields] print(resultlist)
for循环实现:
for webElement in webElements: resutlist = [] fields = webElement.find_elements_by_css_selector('span') for field in fields: resutlist.append(field.text) print(resutlist)