I save in the project array.

I can not save to .csv , writes writerow() , separated by a comma, there is no content from the project array.

Where can there be a mistake?

 def get_parse(html): soup = BS(html, 'lxml') hrefs = soup.find_all('a', class_='address') for inc,aa in enumerate(hrefs, start=1): soup= BS(get_html(aa.get('href')), 'lxml') rot = soup.find_all('a', class_="green dhide") project = [] for ii in rot: namber = ii.text project.append({ 'Modile' : namber }) return (project) def save(project, path): with open(path, 'w') as csvfile: writer = csv.writer(csvfile) writer.writerow(('Namber modile')) for lists in project: writer.writerow(lists['Mobile']) def main(): project = [] for page in range(1, 2): base_url = url + 'page=%d'% page + '&size=10' inc = get_parse(get_html(base_url)) save(project, 'mob_tel.csv') if __name__ == '__main__': main() 
  • one
    It is not customary to show the code as pictures; replace the picture with your code ( править button). If an error occurred while executing the code, then add its text to the question. Thank. - gil9red
  • Replaced the picture code. There is no error, it does not save. - Pavel Melnik
  • Thank you for replacing, it has become so much more convenient. But the formatting has just disappeared in the code and the code has become invalid, please correct the indents. And so, I immediately noticed that you have several project = [] variables, most likely you need to transfer project = [] parameter to get_parse , and that project = [] , which is removed from the function - gil9red
  • If the variable is not assigned a value, then it will not. - Enikeyschik
  • No results. project = [] passed the parameter inside get_parse, and project = [], which was deleted inside the function. - Pavel Melnik

0