Hi, ich muss euch leider nochmal nerven. Ich versuche aus einer Webseite ein paar Daten zu holen und diese in einer Excel zu speichern. Zum Teil geht das auch. In der Excel wird mir das leider falsch dargestellt.
1 | # coding: utf-8
|
2 | import csv |
3 | import xlsxwriter |
4 | from bs4 import BeautifulSoup |
5 | from urllib.request import urlopen |
6 | |
7 | |
8 | soup = BeautifulSoup (urlopen("pfad zur url"), "html.parser") |
9 | |
10 | |
11 | results = soup.find_all("li", {"class": "lvlg"}) |
12 | for result in results: |
13 | result1 = result.get_text().strip() |
14 | result1_new = result1.replace('000', '1') |
15 | #print([result1_new])
|
16 | list_lvlg.append(result1_new) |
17 | str1 = ''.join(list_lvlg) |
18 | #print (str1)
|
19 | |
20 | |
21 | |
22 | |
23 | #Ausgabe xlsx
|
24 | |
25 | workbook = xlsxwriter.Workbook('demo.xlsx') |
26 | worksheet = workbook.add_worksheet("DE") |
27 | |
28 | |
29 | worksheet.write_string(0, 0, str1) |
30 | |
31 | |
32 | workbook.close() |
In Excel wird alles in einer Zelle dargestellt.
1 | 98 79 39 79 29 79 |
Ich möchte das allerdings untereinader mit Zeilenumbruch haben
1 | 98 |
2 | 79 |
3 | 39 |
4 | 79 |
5 | 29 |
6 | 79 |