bsenst commited on
Commit
e96cebb
·
2 Parent(s): 3cfdcf2 5b3bf54

Merge branch 'add-bonus-tutorials'

Browse files
src/04_use_case_bonus/events/_dbd423b9-5d05-4857-a0be-b7136518e7ff.jpeg ADDED
src/04_use_case_bonus/events/veranstaltungen_aggregieren.ipynb ADDED
@@ -0,0 +1,172 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "---\n",
8
+ "title: \"Von HTML zu CSV: Veranstaltungsinformationen sammeln\"\n",
9
+ "description: \"Veranstaltungsinformationen mit BeautifulSoup und Pandas extrahiert und aufbereitet.\"\n",
10
+ "image: _dbd423b9-5d05-4857-a0be-b7136518e7ff.jpeg\n",
11
+ "---"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "markdown",
16
+ "metadata": {},
17
+ "source": [
18
+ "::: {.callout-tip}\n",
19
+ "## Lernziele\n",
20
+ "\n",
21
+ "* Lernen, wie man spezifische HTML-Elemente extrahiert. Anwendung von Selektoren zur gezielten Extraktion von Text aus HTML-Elementen wie `<h2 class=\"teaser__title\">`, `<p class=\"teaser__subtitle\">`, usw.\n",
22
+ "* Verstehen, wie man Informationen über Veranstaltungen in der politischen Bildung in Brandenburg sammelt und analysiert, um sie für weiterführende Projekte oder Studien zu nutzen.\n",
23
+ ":::"
24
+ ]
25
+ },
26
+ {
27
+ "cell_type": "markdown",
28
+ "metadata": {},
29
+ "source": [
30
+ "[![](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/#fileId=https://huggingface.co/spaces/datenwerkzeuge/CDL-Webscraping-Workshop-2025/blob/main/src/04_use_case_bonus/events/veranstaltungen_aggregieren.ipynb)"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "execution_count": 1,
36
+ "metadata": {
37
+ "id": "EsBwSUgTzKLH"
38
+ },
39
+ "outputs": [],
40
+ "source": [
41
+ "# bundeszentrale für politische bildung bietet RSS für veranstaltungen https://www.bpb.de/die-bpb/ueber-uns/service/rss/\n",
42
+ "# an anderer stelle kommt bei fehlen von RSS oder API, scraping in betracht"
43
+ ]
44
+ },
45
+ {
46
+ "cell_type": "code",
47
+ "execution_count": 2,
48
+ "metadata": {
49
+ "id": "wUuU7z1jxzTf"
50
+ },
51
+ "outputs": [],
52
+ "source": [
53
+ "# view-source:https://www.politische-bildung-brandenburg.de/veranstaltungen?page=2"
54
+ ]
55
+ },
56
+ {
57
+ "cell_type": "code",
58
+ "execution_count": null,
59
+ "metadata": {
60
+ "colab": {
61
+ "base_uri": "https://localhost:8080/"
62
+ },
63
+ "id": "aHP0vByew7PX",
64
+ "outputId": "301f3797-99ab-463f-9448-b925e1f01a1e"
65
+ },
66
+ "outputs": [],
67
+ "source": [
68
+ "# prompt: bitte extrahiere alle article elemente aus dem html dokument und extrahiere den text der folgenden element in jedem article element : <h2 class=\"teaser__title\">\n",
69
+ "# <p class=\"teaser__subtitle\">\n",
70
+ "# <p class=\"teaser__meta\">\n",
71
+ "# <p class=\"teaser__kicker\">\n",
72
+ "# <p class=\"teaser__data\">\n",
73
+ "\n",
74
+ "import requests\n",
75
+ "from bs4 import BeautifulSoup\n",
76
+ "\n",
77
+ "url = \"https://www.politische-bildung-brandenburg.de/veranstaltungen\"\n",
78
+ "\n",
79
+ "extracted_data = []\n",
80
+ "\n",
81
+ "for page in range(1, 10):\n",
82
+ " url = f\"https://www.politische-bildung-brandenburg.de/veranstaltungen?page={page}\"\n",
83
+ " try:\n",
84
+ " response = requests.get(url)\n",
85
+ " response.raise_for_status()\n",
86
+ "\n",
87
+ " soup = BeautifulSoup(response.content, \"html.parser\")\n",
88
+ "\n",
89
+ " articles = soup.find_all(\"article\")\n",
90
+ "\n",
91
+ "\n",
92
+ " for article in articles:\n",
93
+ " title = article.find(\"h2\", class_=\"teaser__title\")\n",
94
+ " subtitle = article.find(\"p\", class_=\"teaser__subtitle\")\n",
95
+ " meta = article.find(\"p\", class_=\"teaser__meta\")\n",
96
+ " date = article.find(\"p\", class_=\"teaser__kicker\")\n",
97
+ " location = article.find(\"p\", class_=\"teaser__data\") # corrected class name\n",
98
+ "\n",
99
+ " extracted_data.append({\n",
100
+ " \"title\": title.text.strip() if title else None,\n",
101
+ " \"subtitle\": subtitle.text.strip() if subtitle else None,\n",
102
+ " \"meta\": meta.text.strip() if meta else None,\n",
103
+ " \"date\": date.text.strip() if date else None,\n",
104
+ " \"location\": location.text.strip() if location else None\n",
105
+ " })\n",
106
+ "\n",
107
+ " print(url, len(articles))\n",
108
+ " if len(articles) == 0:\n",
109
+ " break\n",
110
+ "\n",
111
+ " except requests.exceptions.RequestException as e:\n",
112
+ " print(f\"An error occurred during the request: {e}\")\n",
113
+ " except Exception as e:\n",
114
+ " print(f\"An error occurred during processing: {e}\")"
115
+ ]
116
+ },
117
+ {
118
+ "cell_type": "code",
119
+ "execution_count": 4,
120
+ "metadata": {
121
+ "id": "vqxi7Fkkyogw"
122
+ },
123
+ "outputs": [],
124
+ "source": [
125
+ "import pandas as pd\n",
126
+ "\n",
127
+ "df = pd.DataFrame(extracted_data)"
128
+ ]
129
+ },
130
+ {
131
+ "cell_type": "code",
132
+ "execution_count": 5,
133
+ "metadata": {
134
+ "id": "u41T06D7y6Yk"
135
+ },
136
+ "outputs": [],
137
+ "source": [
138
+ "df.to_csv(\"extracted_events.csv\")"
139
+ ]
140
+ },
141
+ {
142
+ "cell_type": "code",
143
+ "execution_count": null,
144
+ "metadata": {
145
+ "colab": {
146
+ "base_uri": "https://localhost:8080/",
147
+ "height": 1000
148
+ },
149
+ "id": "4R46y6phy8xU",
150
+ "outputId": "0d466855-efba-4c94-9e34-c99851d165ce"
151
+ },
152
+ "outputs": [],
153
+ "source": [
154
+ "pd.read_csv(\"extracted_events.csv\", index_col=0)"
155
+ ]
156
+ }
157
+ ],
158
+ "metadata": {
159
+ "colab": {
160
+ "provenance": []
161
+ },
162
+ "kernelspec": {
163
+ "display_name": "Python 3",
164
+ "name": "python3"
165
+ },
166
+ "language_info": {
167
+ "name": "python"
168
+ }
169
+ },
170
+ "nbformat": 4,
171
+ "nbformat_minor": 0
172
+ }
src/04_use_case_bonus/news/_5e53f950-55e9-4158-9404-88d41af64cfb.jpeg ADDED
src/04_use_case_bonus/news/zeitungsartikel.ipynb ADDED
@@ -0,0 +1,181 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "---\n",
8
+ "title: \"Nachrichten-Data Mining\"\n",
9
+ "description: \"Extraktion und Analyse von Nachrichtenartikeln mithilfe von Python und spezifischen Bibliotheken wie newspaper3k.\"\n",
10
+ "image: _5e53f950-55e9-4158-9404-88d41af64cfb.jpeg\n",
11
+ "---"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "markdown",
16
+ "metadata": {},
17
+ "source": [
18
+ "::: {.callout-tip}\n",
19
+ "## Lernziele\n",
20
+ "\n",
21
+ "* Entwicklung von Fähigkeiten zur Erstellung von Skripten, die wiederholt Nachrichtenartikel von einer bestimmten Quelle sammeln und analysieren können.\n",
22
+ "* Methoden der newspaper-Bibliothek, wie build, download, parse und nlp, zur Verarbeitung und Analyse von Nachrichtenartikeln.\n",
23
+ "* Einblick in die Struktur von Nachrichten-Webseiten und wie diese für analytische Zwecke genutzt werden können.\n",
24
+ ":::\n",
25
+ "\n",
26
+ "[RSS Feeds der Süddeutschen Zeitung in der Übersicht ](https://www.sueddeutsche.de/service/updates-mit-rss-uebersicht-aller-rss-feeds-fuer-sz-de-sz-magazin-und-jetzt-de-1.393950)"
27
+ ]
28
+ },
29
+ {
30
+ "cell_type": "markdown",
31
+ "metadata": {},
32
+ "source": [
33
+ "[![](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/#fileId=https://huggingface.co/spaces/datenwerkzeuge/CDL-Webscraping-Workshop-2025/blob/main/src/04_use_case_bonus/news/zeitungsartikel.ipynb)"
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "code",
38
+ "execution_count": null,
39
+ "metadata": {
40
+ "colab": {
41
+ "base_uri": "https://localhost:8080/"
42
+ },
43
+ "id": "Y1uXvjoY4fap",
44
+ "outputId": "95e6c22b-5b37-47ab-f1ec-f5aac34c1f3f"
45
+ },
46
+ "outputs": [],
47
+ "source": [
48
+ "! pip install newspaper3k -q"
49
+ ]
50
+ },
51
+ {
52
+ "cell_type": "code",
53
+ "execution_count": null,
54
+ "metadata": {
55
+ "colab": {
56
+ "base_uri": "https://localhost:8080/"
57
+ },
58
+ "id": "gFRiyo7M4xZ_",
59
+ "outputId": "096a2225-ecfa-4e4c-bc88-f1e9f5ba03eb"
60
+ },
61
+ "outputs": [],
62
+ "source": [
63
+ "! pip install lxml_html_clean -q # Install the required package"
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": null,
69
+ "metadata": {
70
+ "id": "rGGgwoZa4pRo"
71
+ },
72
+ "outputs": [],
73
+ "source": [
74
+ "import newspaper"
75
+ ]
76
+ },
77
+ {
78
+ "cell_type": "code",
79
+ "execution_count": 8,
80
+ "metadata": {
81
+ "id": "6eejA6K0484J"
82
+ },
83
+ "outputs": [],
84
+ "source": [
85
+ "sueddeutsche_paper = newspaper.build('https://www.sueddeutsche.de/')"
86
+ ]
87
+ },
88
+ {
89
+ "cell_type": "code",
90
+ "execution_count": null,
91
+ "metadata": {
92
+ "colab": {
93
+ "base_uri": "https://localhost:8080/"
94
+ },
95
+ "id": "-XjEtFnv5Q8u",
96
+ "outputId": "3c2efabd-bec2-4af2-bb63-c952cd1d6816"
97
+ },
98
+ "outputs": [],
99
+ "source": [
100
+ "for article in sueddeutsche_paper.articles:\n",
101
+ " print(article.url)"
102
+ ]
103
+ },
104
+ {
105
+ "cell_type": "code",
106
+ "execution_count": null,
107
+ "metadata": {
108
+ "colab": {
109
+ "base_uri": "https://localhost:8080/"
110
+ },
111
+ "id": "q44TXocf5cHg",
112
+ "outputId": "16d01c1e-6cc9-4882-aeee-1e46f2c63859"
113
+ },
114
+ "outputs": [],
115
+ "source": [
116
+ "for category in sueddeutsche_paper.category_urls():\n",
117
+ " print(category)"
118
+ ]
119
+ },
120
+ {
121
+ "cell_type": "code",
122
+ "execution_count": null,
123
+ "metadata": {
124
+ "colab": {
125
+ "base_uri": "https://localhost:8080/"
126
+ },
127
+ "id": "QlVcueZQ55I4",
128
+ "outputId": "7226d35d-3a6b-4399-8cd3-9ec2e92ac404"
129
+ },
130
+ "outputs": [],
131
+ "source": [
132
+ "import nltk\n",
133
+ "nltk.download('punkt_tab')"
134
+ ]
135
+ },
136
+ {
137
+ "cell_type": "code",
138
+ "execution_count": 13,
139
+ "metadata": {
140
+ "id": "x2FsV8a-5mEh"
141
+ },
142
+ "outputs": [],
143
+ "source": [
144
+ "sueddeutsche_article = sueddeutsche_paper.articles[0]\n",
145
+ "sueddeutsche_article.download()\n",
146
+ "sueddeutsche_article.parse()\n",
147
+ "sueddeutsche_article.nlp()"
148
+ ]
149
+ },
150
+ {
151
+ "cell_type": "code",
152
+ "execution_count": null,
153
+ "metadata": {
154
+ "colab": {
155
+ "base_uri": "https://localhost:8080/",
156
+ "height": 105
157
+ },
158
+ "id": "lKem_ggG6CoY",
159
+ "outputId": "cbd0d8c9-a66b-4deb-b94e-94a3ebab4fe3"
160
+ },
161
+ "outputs": [],
162
+ "source": [
163
+ "sueddeutsche_article.text"
164
+ ]
165
+ }
166
+ ],
167
+ "metadata": {
168
+ "colab": {
169
+ "provenance": []
170
+ },
171
+ "kernelspec": {
172
+ "display_name": "Python 3",
173
+ "name": "python3"
174
+ },
175
+ "language_info": {
176
+ "name": "python"
177
+ }
178
+ },
179
+ "nbformat": 4,
180
+ "nbformat_minor": 0
181
+ }
src/04_use_case_bonus/trend-monitoring/_3e3e2e53-2755-4ee2-b245-7222dc1ae7f8.jpeg ADDED
src/04_use_case_bonus/trend-monitoring/innovationsmanagement.ipynb ADDED
@@ -0,0 +1,129 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "---\n",
8
+ "title: \"Pytrends zur Analyse von Suchinteresse\"\n",
9
+ "description: \"Nutzung der Pytrends-Bibliothek für die Analyse des Suchinteresses.\"\n",
10
+ "image: _3e3e2e53-2755-4ee2-b245-7222dc1ae7f8.jpeg\n",
11
+ "---"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "markdown",
16
+ "metadata": {},
17
+ "source": [
18
+ "::: {.callout-tip}\n",
19
+ "## Lernziele\n",
20
+ "\n",
21
+ "* Grundlegende Manipulation und Analyse von Zeitreihendaten in Pandas DataFrames.\n",
22
+ "* Analyse und Interpretation von Trends in der Internet-Suchverhaltensdaten, was nützlich für Marktforschung sein kann.\n",
23
+ ":::"
24
+ ]
25
+ },
26
+ {
27
+ "cell_type": "markdown",
28
+ "metadata": {},
29
+ "source": [
30
+ "[![](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/#fileId=https://huggingface.co/spaces/datenwerkzeuge/CDL-Webscraping-Workshop-2025/blob/main/src/04_use_case_bonus/trend-monitoring/innovationsmanagement.ipynb)"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "execution_count": null,
36
+ "metadata": {
37
+ "id": "FTMJrfp61duL"
38
+ },
39
+ "outputs": [],
40
+ "source": [
41
+ "# https://trends.google.com/trends/"
42
+ ]
43
+ },
44
+ {
45
+ "cell_type": "code",
46
+ "execution_count": 2,
47
+ "metadata": {
48
+ "id": "szDfBN0F0ZjE"
49
+ },
50
+ "outputs": [],
51
+ "source": [
52
+ "! pip install pytrends -q"
53
+ ]
54
+ },
55
+ {
56
+ "cell_type": "code",
57
+ "execution_count": 3,
58
+ "metadata": {
59
+ "id": "fUe4GvOY0TkW"
60
+ },
61
+ "outputs": [],
62
+ "source": [
63
+ "from pytrends.request import TrendReq\n",
64
+ "\n",
65
+ "pytrends = TrendReq(hl='en-US', tz=360)"
66
+ ]
67
+ },
68
+ {
69
+ "cell_type": "code",
70
+ "execution_count": 4,
71
+ "metadata": {
72
+ "id": "F6Gl7RpF0eo8"
73
+ },
74
+ "outputs": [],
75
+ "source": [
76
+ "kw_list = [\"Blockchain\"]\n",
77
+ "pytrends.build_payload(kw_list, cat=0, timeframe='today 5-y', geo='', gprop='')"
78
+ ]
79
+ },
80
+ {
81
+ "cell_type": "code",
82
+ "execution_count": null,
83
+ "metadata": {
84
+ "colab": {
85
+ "base_uri": "https://localhost:8080/",
86
+ "height": 1000
87
+ },
88
+ "id": "8144JVpI0hn7",
89
+ "outputId": "ef9f123d-9cbc-42c4-ad22-d53108720d50"
90
+ },
91
+ "outputs": [],
92
+ "source": [
93
+ "pytrends.interest_over_time()"
94
+ ]
95
+ },
96
+ {
97
+ "cell_type": "code",
98
+ "execution_count": null,
99
+ "metadata": {
100
+ "colab": {
101
+ "base_uri": "https://localhost:8080/",
102
+ "height": 410
103
+ },
104
+ "id": "321ielTs0sPK",
105
+ "outputId": "c8dbb162-268a-4352-9970-1e3c7c408ea1"
106
+ },
107
+ "outputs": [],
108
+ "source": [
109
+ "from matplotlib import pyplot as plt\n",
110
+ "_df_2['Blockchain'].plot(kind='line', figsize=(8, 4), title='Blockchain')\n",
111
+ "plt.gca().spines[['top', 'right']].set_visible(False)"
112
+ ]
113
+ }
114
+ ],
115
+ "metadata": {
116
+ "colab": {
117
+ "provenance": []
118
+ },
119
+ "kernelspec": {
120
+ "display_name": "Python 3",
121
+ "name": "python3"
122
+ },
123
+ "language_info": {
124
+ "name": "python"
125
+ }
126
+ },
127
+ "nbformat": 4,
128
+ "nbformat_minor": 0
129
+ }
src/_quarto.yml CHANGED
@@ -106,7 +106,14 @@ website:
106
  - section: "Anwendungsfall Bonus"
107
  contents:
108
  - href: 04_use_case_bonus/podcasts/aggregate_podcast_episodes_to_markdown.ipynb
109
- text: "Podcasts aggregieren"
 
 
 
 
 
 
 
110
 
111
  format:
112
  html:
 
106
  - section: "Anwendungsfall Bonus"
107
  contents:
108
  - href: 04_use_case_bonus/podcasts/aggregate_podcast_episodes_to_markdown.ipynb
109
+ text: "Podcasts aggregieren"
110
+ - href: 04_use_case_bonus/news/zeitungsartikel.ipynb
111
+ text: "Nachrichten-Data Mining"
112
+ - href: 04_use_case_bonus/trend-monitoring/innovationsmanagement.ipynb
113
+ text: "Pytrends & Suchinteresse"
114
+ - href: 04_use_case_bonus/events/veranstaltungen_aggregieren.ipynb
115
+ text: "Veranstaltungen sammeln
116
+ "
117
 
118
  format:
119
  html: