Created
May 16, 2023 08:28
-
-
Save nonZero/6b3fd6304bebb2c72fdec1d79d5d0eb0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"id": "c13b2613-b953-4e57-b405-e5c5e3236886", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import requests\n", | |
"from bs4 import BeautifulSoup" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 37, | |
"id": "e3088b8e-80ae-4cd3-b2b7-d1d6a8512edd", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def get_data(soup):\n", | |
" facts = []\n", | |
" for tr in soup.find_all(\"tr\", bgcolor=[\"#CCFFCC\", \"#EDF3FE\"]):\n", | |
" txt = tr.text\n", | |
" if author := tr.find(\"font\", size=\"-1\"):\n", | |
" author = author.text\n", | |
" txt = txt.replace(author, \"\")\n", | |
" author = author.replace('נכתב ע\"י', \"\")\n", | |
" facts.append({'txt': txt.strip(), 'author': author})\n", | |
" \n", | |
" return {\n", | |
" 'title': soup.find(\"font\", size=\"+5\").text,\n", | |
" 'artist': soup.find(\"font\", size=\"+2\").text,\n", | |
" 'facts': facts,\n", | |
" }" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 44, | |
"id": "2ea2fa1c-7457-4c52-8b38-4fd372105d5f", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"def get_song_data(id):\n", | |
" url = f\"https://mima.co.il/fact_page.php?song_id={id}\"\n", | |
" r = requests.get(url)\n", | |
" soup = BeautifulSoup(r.text, \"html.parser\")\n", | |
" return {\"id\": id, **get_data(soup)}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 45, | |
"id": "d4f4c3da-1e64-449f-a803-b9251d6f224f", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'id': 547,\n", | |
" 'title': 'בהאחזות הנח\"ל בסיני',\n", | |
" 'artist': 'להקת הנח\"ל',\n", | |
" 'facts': [{'txt': '\"שם כל השרות והדליות והרינות \\r\\nפסעו לאט בתוך שדרת קזוארינות\"\\r\\n\\r\\nקזוארינה (ברבים קזוארינות) הוא עץ ממשפחת האורניים.',\n", | |
" 'author': None},\n", | |
" {'txt': '\"שירי רחל וכוכבים בחוץ\" \\r\\nכוכבים בחוץ הוא שיר של אלתרמן, שנתן את שמו לאחד מספריו.',\n", | |
" 'author': ' גליה '},\n", | |
" {'txt': 'מירי אלוני, הסולנית, האזינה היטב לביצוע המקורי של השיר, שבוצע ע\"י נעמי שמר עצמה, ולדבריה: למדה ממנה הרבה כיצד לשיר את השיר בעדינות ובהתרפקות נוסטלגית.',\n", | |
" 'author': ' גליה '},\n", | |
" {'txt': 'מולי שפירא בתוכניתו \"בילוי נעים\" בגל\"צ סיפר שהזמינו את נעמי שמר לתכנית ברדיו, שתיערך בהיאחזות הנחל בסיני. שמר כל-כך התרשמה והתרגשה, שמיד אחר-כך התיישבה וכתבה את השיר.',\n", | |
" 'author': ' גליה '},\n", | |
" {'txt': 'למרות הסברה של שמר (בראיון עיתונאי בשנות התשעים) שבאותו יום סיירה בכמה היאחזויות, אז \"כל היאחזות שתגיד שהשיר עליה- תצדק\", יצויין שהשורה \"ובחצר היו החיילים צולים דגים גדולים\" מצביעה על כך שההיאחזות ביחס לשורה הספציפית הזו היא \\'נח\"ל-ים\" (בגלל הקרבה לחוף).',\n", | |
" 'author': ' מלח הארץ '},\n", | |
" {'txt': 'הקליפ המפורסם של השיר צולם בהיאחזות נח\"ל סיני.',\n", | |
" 'author': ' ניב '}]}" | |
] | |
}, | |
"execution_count": 45, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"get_song_data(547)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 41, | |
"id": "1b97f02a-c157-41c7-aaa0-7c03fd5961b9", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'title': 'אהובתי',\n", | |
" 'artist': 'משינה',\n", | |
" 'facts': [{'txt': 'Baby Baby,\\r\\n\\r\\nכך תורגם שם השיר על העטיפה.',\n", | |
" 'author': ' לאה '}]}" | |
] | |
}, | |
"execution_count": 41, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"get_song_data(200)\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 42, | |
"id": "0b7f5a7a-6ccf-44e1-be0c-486f72480345", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"from tqdm.contrib.concurrent import thread_map" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 43, | |
"id": "76b95e04-fb87-4c3c-9d55-b6f6e076110f", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"ids = list(range(1, 101))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 47, | |
"id": "076c7066-e8d2-446a-8c06-eb0f7a4f0545", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "7f85f2c97f8d43e7a2833b5f68843f14", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
" 0%| | 0/100 [00:00<?, ?it/s]" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"info = thread_map(get_song_data, ids)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 48, | |
"id": "0a083891-6769-4a60-bd53-7785d040f4bb", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"100" | |
] | |
}, | |
"execution_count": 48, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"len(info)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 49, | |
"id": "d5a20a2d-0641-4adc-8aa9-056830c9364f", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'id': 26,\n", | |
" 'title': 'בבוקר של קטיפה',\n", | |
" 'artist': 'רמי פורטיס',\n", | |
" 'facts': [{'txt': 'שיר עם גוון פסיכודלי מתוך האלבום \"סיפורים מהקופסה\".',\n", | |
" 'author': None},\n", | |
" {'txt': 'מבוסס על שיר אמריקאי מ-68\\' בשם \"Some Velvet Morning\\'\", שבוצע במקור ע\"י ננסי סינטרה (הבת של) ולי הייזלווד.',\n", | |
" 'author': None},\n", | |
" {'txt': 'התרגום לעברית הוא של סמי בירנבך, הסולן של מינימל קומפקט.',\n", | |
" 'author': None},\n", | |
" {'txt': 'את הפזמון המלאכי שרה סאלי לדרמן, ביתו של יוסי לדרמן, שעשה עבודת מחשב וסימפולים בתקליט:',\n", | |
" 'author': ' דודו '},\n", | |
" {'txt': '\"בוא אספר לך על פדרה\"\\r\\n\\r\\nבמיתולגיה היוונית,פדרה היא נכדתו של זאוס,בתו של מינוס מלך כרתים ואשתו של תזאוס.',\n", | |
" 'author': ' יונה '}]}" | |
] | |
}, | |
"execution_count": 49, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"info[25]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "f3387f1c-1d4e-48f9-9cda-cd5a3397c54f", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"%gist get_songs.ipynb" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.10.11" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment