Skip to content

Commit 1ab0b88

Browse files
committed
adding table to notebook
1 parent 1d09a8b commit 1ab0b88

File tree

1 file changed

+121
-17
lines changed

1 file changed

+121
-17
lines changed

Notebooks/23_Intro_Scraping.ipynb

Lines changed: 121 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
{
1313
"cell_type": "code",
14-
"execution_count": 1,
14+
"execution_count": 14,
1515
"metadata": {},
1616
"outputs": [],
1717
"source": [
@@ -39,7 +39,7 @@
3939
},
4040
{
4141
"cell_type": "code",
42-
"execution_count": 2,
42+
"execution_count": 3,
4343
"metadata": {},
4444
"outputs": [
4545
{
@@ -48,7 +48,7 @@
4848
"12"
4949
]
5050
},
51-
"execution_count": 2,
51+
"execution_count": 3,
5252
"metadata": {},
5353
"output_type": "execute_result"
5454
}
@@ -61,7 +61,7 @@
6161
},
6262
{
6363
"cell_type": "code",
64-
"execution_count": 77,
64+
"execution_count": 4,
6565
"metadata": {},
6666
"outputs": [
6767
{
@@ -160,7 +160,7 @@
160160
"4 5.0 Innsbruck 118112 113392 126851 Tyrol"
161161
]
162162
},
163-
"execution_count": 77,
163+
"execution_count": 4,
164164
"metadata": {},
165165
"output_type": "execute_result"
166166
}
@@ -171,7 +171,7 @@
171171
},
172172
{
173173
"cell_type": "code",
174-
"execution_count": 4,
174+
"execution_count": 5,
175175
"metadata": {},
176176
"outputs": [
177177
{
@@ -250,7 +250,7 @@
250250
"4 Burgenland Bad Tatzmannsdorf Other municipality 1554"
251251
]
252252
},
253-
"execution_count": 4,
253+
"execution_count": 5,
254254
"metadata": {},
255255
"output_type": "execute_result"
256256
}
@@ -268,7 +268,7 @@
268268
},
269269
{
270270
"cell_type": "code",
271-
"execution_count": 79,
271+
"execution_count": 6,
272272
"metadata": {},
273273
"outputs": [
274274
{
@@ -301,7 +301,7 @@
301301
},
302302
{
303303
"cell_type": "code",
304-
"execution_count": 80,
304+
"execution_count": 7,
305305
"metadata": {},
306306
"outputs": [
307307
{
@@ -310,7 +310,7 @@
310310
"'<!DOCTYPE html>\\n<html lang=\"de\">\\n<head>\\n<meta charset=\"utf-8\" />\\n<meta http-equiv=\"cache-control\" content=\"no-cache\" />\\n<meta http-equiv=\"pragma\" content=\"no-cache\" />\\n<meta name=\"robots\" content=\"index, follow, noarchive\" />\\n<meta name=\"content-language\" content=\"de\" />\\n<meta name=\"description\" content=\"Am Donnerstag ging es zwar &quot;nur&quot; um eine Impfkampagne. Der steirische Landeshauptmann Hermann Sch&uuml;tzenh&ouml;fer plant aber die Corona-Impfung als Voraussetzung bei Neueinstellung von Kindergartenpersonal.\" />\\n<meta name=\"author\" content=\"Martina Madner\" />\\n<meta name=\"copyright\" content=\"Wiener Zeitung Online\" />\\n<meta property=\"og:type\" content=\"article\" />\\n<meta property=\"og:title\" content=\"Impfpflicht - H&auml;rtere steirische Impfanreize\" />\\n<meta property=\"og:description\" content=\"Am Donnerstag ging es zwar &quot;nur&quot; um eine Impfkampagne. Der steirische Landeshauptmann Hermann Sch&uuml;tzenh&ouml;fer plant aber die Corona-Impfung als...\" />\\n<meta property=\"og'"
311311
]
312312
},
313-
"execution_count": 80,
313+
"execution_count": 7,
314314
"metadata": {},
315315
"output_type": "execute_result"
316316
}
@@ -328,7 +328,7 @@
328328
},
329329
{
330330
"cell_type": "code",
331-
"execution_count": 81,
331+
"execution_count": 8,
332332
"metadata": {},
333333
"outputs": [
334334
{
@@ -344,6 +344,110 @@
344344
"print(type(soup))"
345345
]
346346
},
347+
{
348+
"cell_type": "markdown",
349+
"metadata": {},
350+
"source": [
351+
"#### A quick note on parsers:"
352+
]
353+
},
354+
{
355+
"cell_type": "code",
356+
"execution_count": 23,
357+
"metadata": {},
358+
"outputs": [
359+
{
360+
"data": {
361+
"text/html": [
362+
"<div>\n",
363+
"<style scoped>\n",
364+
" .dataframe tbody tr th:only-of-type {\n",
365+
" vertical-align: middle;\n",
366+
" }\n",
367+
"\n",
368+
" .dataframe tbody tr th {\n",
369+
" vertical-align: top;\n",
370+
" }\n",
371+
"\n",
372+
" .dataframe thead th {\n",
373+
" text-align: right;\n",
374+
" }\n",
375+
"</style>\n",
376+
"<table border=\"1\" class=\"dataframe\">\n",
377+
" <thead>\n",
378+
" <tr style=\"text-align: right;\">\n",
379+
" <th></th>\n",
380+
" <th>Parser</th>\n",
381+
" <th>Typical usage</th>\n",
382+
" <th>Advantages</th>\n",
383+
" <th>Disadvantages</th>\n",
384+
" </tr>\n",
385+
" </thead>\n",
386+
" <tbody>\n",
387+
" <tr>\n",
388+
" <th>1</th>\n",
389+
" <td>Python’s html.parser</td>\n",
390+
" <td>BeautifulSoup(markup, \"html.parser\")</td>\n",
391+
" <td>Batteries included Decent speed Lenient (As of...</td>\n",
392+
" <td>Not as fast as lxml, less lenient than html5lib.</td>\n",
393+
" </tr>\n",
394+
" <tr>\n",
395+
" <th>2</th>\n",
396+
" <td>lxml’s HTML parser</td>\n",
397+
" <td>BeautifulSoup(markup, \"lxml\")</td>\n",
398+
" <td>Very fast Lenient</td>\n",
399+
" <td>External C dependency</td>\n",
400+
" </tr>\n",
401+
" <tr>\n",
402+
" <th>3</th>\n",
403+
" <td>lxml’s XML parser</td>\n",
404+
" <td>BeautifulSoup(markup, \"lxml-xml\") BeautifulSou...</td>\n",
405+
" <td>Very fast The only currently supported XML parser</td>\n",
406+
" <td>External C dependency</td>\n",
407+
" </tr>\n",
408+
" <tr>\n",
409+
" <th>4</th>\n",
410+
" <td>html5lib</td>\n",
411+
" <td>BeautifulSoup(markup, \"html5lib\")</td>\n",
412+
" <td>Extremely lenient Parses pages the same way a ...</td>\n",
413+
" <td>Very slow External Python dependency</td>\n",
414+
" </tr>\n",
415+
" </tbody>\n",
416+
"</table>\n",
417+
"</div>"
418+
],
419+
"text/plain": [
420+
"0 Parser Typical usage \\\n",
421+
"1 Python’s html.parser BeautifulSoup(markup, \"html.parser\") \n",
422+
"2 lxml’s HTML parser BeautifulSoup(markup, \"lxml\") \n",
423+
"3 lxml’s XML parser BeautifulSoup(markup, \"lxml-xml\") BeautifulSou... \n",
424+
"4 html5lib BeautifulSoup(markup, \"html5lib\") \n",
425+
"\n",
426+
"0 Advantages \\\n",
427+
"1 Batteries included Decent speed Lenient (As of... \n",
428+
"2 Very fast Lenient \n",
429+
"3 Very fast The only currently supported XML parser \n",
430+
"4 Extremely lenient Parses pages the same way a ... \n",
431+
"\n",
432+
"0 Disadvantages \n",
433+
"1 Not as fast as lxml, less lenient than html5lib. \n",
434+
"2 External C dependency \n",
435+
"3 External C dependency \n",
436+
"4 Very slow External Python dependency "
437+
]
438+
},
439+
"execution_count": 23,
440+
"metadata": {},
441+
"output_type": "execute_result"
442+
}
443+
],
444+
"source": [
445+
"df_parsers = pd.read_html(\"https://www.crummy.com/software/BeautifulSoup/bs4/doc/\")[0]\n",
446+
"df_parsers.columns = df_parsers.iloc[0]\n",
447+
"df_parsers.drop(df_parsers.index[0], inplace=True)\n",
448+
"df_parsers.head()"
449+
]
450+
},
347451
{
348452
"cell_type": "markdown",
349453
"metadata": {},
@@ -353,7 +457,7 @@
353457
},
354458
{
355459
"cell_type": "code",
356-
"execution_count": 82,
460+
"execution_count": 9,
357461
"metadata": {},
358462
"outputs": [
359463
{
@@ -391,14 +495,14 @@
391495
},
392496
{
393497
"cell_type": "code",
394-
"execution_count": 84,
498+
"execution_count": 10,
395499
"metadata": {},
396500
"outputs": [
397501
{
398502
"name": "stdout",
399503
"output_type": "stream",
400504
"text": [
401-
"ete Werbekampagne f&uuml;rs Impfen in der Steiermark. Es spricht von einer \\\"gewissen Impfm&uuml;digkeit, die eingetreten ist, da rede ich nicht um den hei&szlig;en Brei herum: Die Anmeldungen sind zur&uuml;ckgegangen.\\\" 560.000 von 1,1 Millionen impfbaren Steirerinnen und Steirern sind erstgeimpft, 227.000 auch ein zweites Mal. Sein Appell: \\\"Wir werden alles versuchen, damit sich die Menschen impfen lassen. Es ist noch nicht vorbei.\\\"<\\/p>\\n<p>In der ORF-\\\"Pressestunde\\\" sprach Sch&uuml;tzenh&ouml;fer von einem \\\"sch&auml;bigem Verhalten\\\" der Impfunwilligen. Auf die Frage, ob er sich eine Sars-CoV-2-Schutzimpfungspflicht f&uuml;r das Kindergartenpersonal vorstellen k&ouml;nne, sagte er: \\\"Ich w&auml;re pers&ouml;nlich daf&uuml;r, der Verfassungsdienst des Bundes sagt aber: Nein, das geht nicht\\\" - und lie&szlig; dann aufhorchen: \\\"Aber: Jedes Land kann selber etwas bei der Aufnahme tun. Das will ich in den Bereichen des Landes selbstverst&auml;ndlich so machen.\\\"<\\/p>\\n<p>Impfnachz&\n"
505+
"un gestartete Werbekampagne f&uuml;rs Impfen in der Steiermark. Es spricht von einer \\\"gewissen Impfm&uuml;digkeit, die eingetreten ist, da rede ich nicht um den hei&szlig;en Brei herum: Die Anmeldungen sind zur&uuml;ckgegangen.\\\" 560.000 von 1,1 Millionen impfbaren Steirerinnen und Steirern sind erstgeimpft, 227.000 auch ein zweites Mal. Sein Appell: \\\"Wir werden alles versuchen, damit sich die Menschen impfen lassen. Es ist noch nicht vorbei.\\\"<\\/p>\\n<p>In der ORF-\\\"Pressestunde\\\" sprach Sch&uuml;tzenh&ouml;fer von einem \\\"sch&auml;bigem Verhalten\\\" der Impfunwilligen. Auf die Frage, ob er sich eine Sars-CoV-2-Schutzimpfungspflicht f&uuml;r das Kindergartenpersonal vorstellen k&ouml;nne, sagte er: \\\"Ich w&auml;re pers&ouml;nlich daf&uuml;r, der Verfassungsdienst des Bundes sagt aber: Nein, das geht nicht\\\" - und lie&szlig; dann aufhorchen: \\\"Aber: Jedes Land kann selber etwas bei der Aufnahme tun. Das will ich in den Bereichen des Landes selbstverst&auml;ndlich so machen.\\\"<\\/p>\\n<p>\n"
402506
]
403507
}
404508
],
@@ -408,7 +512,7 @@
408512
},
409513
{
410514
"cell_type": "code",
411-
"execution_count": 85,
515+
"execution_count": 11,
412516
"metadata": {},
413517
"outputs": [
414518
{
@@ -709,7 +813,7 @@
709813
"cell_type": "markdown",
710814
"metadata": {},
711815
"source": [
712-
"article### Extracting specific information"
816+
"### Extracting specific information"
713817
]
714818
},
715819
{
@@ -3809,7 +3913,7 @@
38093913
"name": "python",
38103914
"nbconvert_exporter": "python",
38113915
"pygments_lexer": "ipython3",
3812-
"version": "3.8.5"
3916+
"version": "3.7.6"
38133917
}
38143918
},
38153919
"nbformat": 4,

0 commit comments

Comments
 (0)