Home>

First python learner.
An array of text data of the specified class of the web page,
I want to make CSV for each person who has commented.

However, only the last person on the page can vomit.

Thanks for your teaching.

Applicable source code
AAA = soup.find_all ('div', class_ = 'xxx')
for BBB in AAA:
 CCC = BBB.getText ()
 DDD = CCC.replace ('\ xa0', '')
 eee = [x.strip () for x in DDD.split ('\ n') if not x.strip () == '']
 print (eee) #Terminal confirmation
with open (r "eee", 'wt', encoding = 'cp932') as file:
    writer = csv.writer (file, lineterminator = ',')
    writer.writerows ([eee])

I wondered if it wasn't a multidimensional array.
Multi-dimensional array can not be made well, CSV output only at the end ('div', class_ = 'xxx').

Supplemental information (FW/tool version etc.)

python: 3.8.0
Windows: 10

  • Answer # 1

    AAA = soup.find_all ('div', class_ = 'xxx')
    with open (r "eee", 'wt', encoding = 'cp932') as file:
        writer = csv.writer (file, lineterminator = ',')
        for BBB in AAA:
            CCC = BBB.getText ()
            DDD = CCC.replace ('\ xa0', '')
            eee = [x.strip () for x in DDD.split ('\ n') if not x.strip () == '']
            writer.writerows ([eee])

Related articles