writing and saving CSV file from scraping data using python and Beautifulsoup4

后端 未结 2 1702
鱼传尺愫
鱼传尺愫 2021-02-03 15:36

I am trying to scrape data from the PGA.com website to get a table of all of the golf courses in the United States. In my CSV table I want to include the Name of the golf course

2条回答
  •  伪装坚强ぢ
    2021-02-03 15:48

    First of all you want to put all of your items in a list and then write to a file later in case there is an error while you are scrapping. Instead of printing just append to a list. Then you can write to a csv file

    f= open('filename', 'wb')
    csv_writer = csv.writer(f)
    for i in main_list:
        csv_writer.writerow(i)
    f.close()
    

提交回复
热议问题