#! usr/bin python3 import csv import urllib.request from bs4 import BeautifulSoup def get_html(url): response = urllib.request.urlopen(url) return response.read() def parse(html): soup = BeautifulSoup(html) search = soup.find('div', class_='search-total js-search-total') span = soup.find('span', class_='search-message js-page-title') spantext = span.text searchtext = search.text print(spantext, searchtext) def save(searchtext, spantext, path): with open(path, 'w') as csvfile: writer = csv.writer(csvfile) writer.writerow(('Название', 'Кол-во')) writer.writerow((spantext['Название'], searchtext['Кол-во'])) save ('project.csv') def main(): parse(get_html('http://www.abitant.com/catalogues/bra-i-nastennye-svetilniki/companies/robers')) if __name__ == '__main__': main() 

Mistake:

 TypeError: save() missing 2 required positional arguments: 'spantext' and 'path' 

Guys, I do not understand how to save the data in a csv file, please help.

  • What data? Examples from the documentation for the module CSV viewed? What exactly is the problem then? - Vladimir Martyanov
  • Yes, the documentation looked, but did not understand. Unable to save file to csv. - Narnik Gamarnik
  • What kind of data is not stored? Make a minimal example where something is not working. - Vladimir Martyanov
  • No csv file is created. - Narnik Gamarnik
  • And once again: what data? Write the minimum code to reproduce the problem in question. - Vladimir Martyanov

1 answer 1

 save ('project.csv') def save(searchtext, spantext, path): 

The interpreter clearly says to you: "2 arguments are missing in the save function"

Why do you even call the save function in such a strange place and without the necessary arguments? Where do you get these arguments at the time of the call?

It should be something like:

 def parse(...): .... print(...) save(searchetxt, spantext, 'project.csv') 
  • Thank you. Blunted ... - Narnik Gamarnik