Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't import csv data
#1
in the code below, page is the webpage response from Playwright for what it's worth:
The csv file gets created ok and looks good as far as I can tell. But then when I go to import this file into a Microsoft Access database, nothing is imported. Is there some sort of conversion that needs to be done before writing the data to the csv file?
Thank you

                for row in page.query_selector_all("table tbody tr"):
                    i += 1
                    link = row.query_selector("xpath=td/a[text()='View']")
                    url = link.get_attribute('href')
                    charges = process_details(url)
                    if charges not in ['', 'err']:
                        charges = fix_charge(charges)
                        print(charges)
                        for charge in charges.split(';'):
                            print('------', charge)
                            record = [
                                    row.query_selector_all("td")[1].inner_text(),
                                    row.query_selector_all("td")[2].inner_text(),
                                    row.query_selector_all("td")[3].inner_text(),
                                    row.query_selector_all("td")[4].inner_text(),
                                    row.query_selector_all("td")[6].inner_text(),
                                    charge.strip().replace(',', ';'),
                                    new_date
                            ]
                            if charge.strip() not in ['', ' ']:
                                output_file.writerow(record)
                page.go_back()
        file.close()


def fix_charge(charge):
    charge = charge[charge.index(' '):].lstrip()

    for num in re.findall('\d+', charge):
        charge = charge.replace(num, '1')
    charge = charge.replace('1.', ';')
    charge = charge.replace('1-', ';')
    charge = charge.replace('1)', ';')
    charge = charge.replace('(1)', ';')
    charge = charge.replace(' 1 ', ';')
    charge = charge.strip().strip(',')
    return charge.strip()
Reply


Messages In This Thread
Can't import csv data - by JonWayn - Sep-16-2022, 10:43 AM
RE: Can't import csv data - by buran - Sep-16-2022, 11:01 AM
RE: Can't import csv data - by JonWayn - Sep-18-2022, 02:01 AM
RE: Can't import csv data - by rob101 - Sep-16-2022, 09:28 PM
RE: Can't import csv data - by JonWayn - Sep-18-2022, 02:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Plot a pandas data fram via pyqtgraph with an modul import and qt designer widget Nietzsche 0 859 May-29-2023, 02:42 PM
Last Post: Nietzsche
Video doing data treatment on a file import-parsing a variable EmBeck87 15 2,917 Apr-17-2023, 06:54 PM
Last Post: EmBeck87
  Python 3.11 data import question love0715 2 822 Mar-05-2023, 06:50 PM
Last Post: snippsat
  I try to import data from Excel table to Word Template. NewbiePyPy 0 3,291 Oct-21-2020, 12:25 PM
Last Post: NewbiePyPy
  Import CSV data into array and turn into integers DoctorSmiles 5 3,224 Jul-16-2020, 10:47 AM
Last Post: perfringo
  How to import data to excel jkessous 4 2,947 Jan-26-2020, 07:53 PM
Last Post: snippsat
  Early data import question VorpalPirate 2 2,266 Dec-09-2019, 10:52 PM
Last Post: snippsat
  How to import data from database to excel nick123 1 3,523 Oct-09-2019, 04:39 PM
Last Post: sm51251
  Import data from excel to Teradata steve87bg 3 4,777 Sep-18-2019, 01:36 PM
Last Post: steve87bg
  Import and/or read IMC measurement data Squipy 0 3,775 Aug-11-2019, 02:48 PM
Last Post: Squipy

Forum Jump:

User Panel Messages

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