Help me import csv



  • #! 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 don't know how to keep the data in the sv file, please.



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

    You know, the interpreter says, "there are two arguments to save."

    Why do you even call the F-saving in such a strange place and without the necessary arguments? Where will you take these arguments at the time of the challenge?

    Must be something like:

    def parse(...):
    

    ....
    print(...)
    save(searchetxt, spantext, 'project.csv')




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2