Python Forum
Trying to save array results to a csv
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to save array results to a csv
#1
Hi,

Basically I'm trying to use the following scraper to scrape data, then save to csv however the examples given are for prints and I can't figure out how to save it instead or how I should be structuring the python file.

https://github.com/realsirjoe/instagram-scraper

Example:
https://github.com/realsirjoe/instagram-...llowers.py


One of my many attempts:
from igramscraper.instagram import Instagram
from time import sleep
import csv

instagram = Instagram()
instagram.with_credentials('user', 'password', '/cachepath')
instagram.login(force=False,two_step_verificator=False)

sleep(2) # Delay to mimic user
with open('test.csv', mode='w') as csv_file:
    fieldnames = ['id', 'username', 'full_name', 'bio', 'profile_pic_url', 'external_url', 'number_of_posts', 'number_of_followers', 'number_of_follows', 'is_private', 'is_verified']
    writer = csv.DictWriter(csv_file, fieldnames=fieldnames)
    writer.writeheader()
sleep(2) # Delay to mimic user

username = 'username'
followers = []
account = instagram.get_account(username)
sleep(1)
followers = instagram.get_followers(account.identifier, 200, 100, delayed=True) # Get 150 followers of 'kevin', 100 a time with random delay between requests

for follower in followers['accounts']:
   csv_file.write(followers)
It logs in and creates the csv file okay but no idea where to go from there.

Also the results from the scraping print it out like so:
Account info:
Id: 196333333333333
Username: username
Full Name: Some Name
Bio: None
Profile Pic Url: None
External url: None
Number of published posts: -
Number of followers: 0
Number of follows: 0
Is private: False
Is verified: False
which probably isn't the best format to try and get into csv? If anyone has any ideas on how to do that bit better (or maybe I'll have to just do a Find/Replace to add commas afterwards? Think ) I'm all ears!


Thanks for any help or input on either problem above!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to save to multiple locations during save cubangt 1 542 Oct-23-2023, 10:16 PM
Last Post: deanhystad
  How to format EasyOCR results in order to save to CSV? cubangt 0 1,250 Sep-02-2022, 02:06 PM
Last Post: cubangt
  How to save some results in .txt file with Python? Melcu54 4 7,304 May-26-2021, 08:15 AM
Last Post: snippsat
  Save Numpy Array in Another Numpy Array (not Concatenate!) quest 1 1,847 Nov-06-2020, 01:06 PM
Last Post: quest
  Search Results Web results Printing the number of days in a given month and year afefDXCTN 1 2,231 Aug-21-2020, 12:20 PM
Last Post: DeaD_EyE
  How to append one function1 results to function2 results SriRajesh 5 3,138 Jan-02-2020, 12:11 PM
Last Post: Killertjuh
  Problems with save array into Mysql storzo 1 2,102 Sep-27-2019, 04:25 PM
Last Post: storzo
  Small help for the python array save juniorcoder 1 2,174 Sep-27-2018, 09:28 AM
Last Post: buran
  Scraping results won't save in csv file origomedia 2 3,018 Sep-23-2017, 01:25 AM
Last Post: origomedia

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020