Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
writing data to a csv-file
#1
Hi there - good day dear python-experts,


i am just trying to get more python-skills.

today i am working on the csv-saving of data.


while i am scraping unstructured data from a website using BeautifulSoup to pull out the data-chunks that I need. Afterwards i want to structure the dataset. I am aiming this coz i think it is best to added the values to a list. And then - afterwards i want to add them to a csv file.

I plan to do this so - with this method, bcause the list gets new values every time the the loop is called.

there is a loop: it is aimed to add permanently new values to the file so that my csv file has values from each turn in the loop.

(the fetching part  that  i arrange with requests )


for i in range(1, 100):
    url = "https://my-website.com/webid={}".format(i)
    s = session.get(url, headers=headers, cookies=cookies)

    soup = bs(s.text, 'html.parser')
    data = soup.find_all('td') 
    t = soup.find_all('td')
    a = t[0]
    b = t[1]
    c = t[2]
    d = t[3]
    e = t[4]
    f = t[5]
    g = t[4]
    info = [a, b, c, d, e, f, g and so on and so forth] <-  [this is my list]
    print(info)

df = pd.DataFrame(info) 				<-  [here  i am writing the stuff to the csv-file]
df.to_csv('a.csv', mode='a', index=False, header=False)
can this be done like so!?

regards yours apollo Smile
Wordpress - super toolkits a. http://wpgear.org/ :: und b. https://github.com/miziomon/awesome-wordpress :: Awesome WordPress: A curated list of amazingly awesome WordPress resources and awesome python things https://github.com/vinta/awesome-python
Reply


Messages In This Thread
writing data to a csv-file - by apollo - Jul-03-2020, 02:08 PM
RE: writing data to a csv-file - by DeaD_EyE - Jul-03-2020, 02:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with writing monitored data to mysql upon change of one particular variable donottrackmymetadata 3 337 Apr-18-2024, 09:55 PM
Last Post: deanhystad
  Issue in writing sql data into csv for decimal value to scientific notation mg24 8 3,114 Dec-06-2022, 11:09 AM
Last Post: mg24
  Create a function for writing to SQL data to csv mg24 4 1,215 Oct-01-2022, 04:30 AM
Last Post: mg24
  Writing string to file results in one character per line RB76SFJPsJJDu3bMnwYM 4 1,414 Sep-27-2022, 01:38 PM
Last Post: buran
  Writing to json file ebolisa 1 1,032 Jul-17-2022, 04:51 PM
Last Post: deanhystad
  Writing to External File DaveG 9 2,552 Mar-30-2022, 06:25 AM
Last Post: bowlofred
  Need Help writing data into Excel format ajitnayak87 8 2,575 Feb-04-2022, 03:00 AM
Last Post: Jeff_t
  Fastest Way of Writing/Reading Data JamesA 1 2,220 Jul-27-2021, 03:52 PM
Last Post: Larz60+
Smile Set 'Time' format cell when writing data to excel and not 'custom' limors 3 6,362 Mar-29-2021, 09:36 PM
Last Post: Larz60+
  Writing to file ends incorrectly project_science 4 2,728 Jan-06-2021, 06:39 PM
Last Post: bowlofred

Forum Jump:

User Panel Messages

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