Created
July 30, 2018 16:35
-
-
Save yi-jiayu/0075eb05688baca41fdb865ae16de953 to your computer and use it in GitHub Desktop.
NLB book info
This file contains 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, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import requests\n", | |
"import pandas as pd\n", | |
"from lxml import etree" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"http://eservice.nlb.gov.sg/item_holding_s.aspx?bid=14375145\n", | |
"http://eservice.nlb.gov.sg/getholding.aspx?bid=14375145\n" | |
] | |
} | |
], | |
"source": [ | |
"bid = '14375145'\n", | |
"details_url = f'http://eservice.nlb.gov.sg/item_holding_s.aspx?bid={bid}'\n", | |
"holding_url = f'http://eservice.nlb.gov.sg/getholding.aspx?bid={bid}'\n", | |
"details_html = requests.get(details_url).text\n", | |
"holding_html = requests.get(holding_url).text\n", | |
"\n", | |
"print(details_url, holding_url, sep='\\n')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\r\n", | |
"\r\n", | |
"<!DOCTYPE html>\r\n", | |
"<html>\r\n", | |
"<head>\r\n", | |
" <!-- Basic Page Needs\r\n", | |
" ================================================== -->\r\n", | |
" <meta charset=\"utf-8\">\r\n", | |
" <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\r\n", | |
" <title>Think like a programmer : an introduction to creative problem solving / V. Anton Spraul.</title>\r\n", | |
" <meta name=\"robots\" content=\"noindex, nofollow\">\r\n", | |
" <meta name=\"description\" content=\"\" />\r\n", | |
" <meta name=\"keywords\" content=\"NLB Catalogue National Library Board, Singapore\" />\r\n", | |
" <meta name=\"author\" content=\"National Library Board, Singapore\" />\r\n", | |
" <!--[if lt IE 9]>\r\n", | |
"\t <script src=\"http://html5shim.googlecode.com/svn/trunk/html5.js\"></script>\r\n", | |
" <![endif]-->\r\n", | |
"\r\n", | |
" <!-- Mobile Specific Metas\r\n", | |
" ================================================== -->\r\n", | |
" <meta name=\"viewport\" content=\"width=device-width, initial-scale=1, maximum-scale=1\">\r\n", | |
"\r\n", | |
" <!-- CSS\r\n", | |
" ================================================== -->\r\n", | |
" <link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheets/main.css\">\r\n", | |
" <!--<link rel=\"stylesheet\" type=\"text/css\" href=\"stylesheets/bootstrap.css\" />-->\r\n", | |
" <link type=\"text/css\" rel=\"Stylesheet\" href=\"//eservice.nlb.gov.sg/components/css/nlb.css\" /> \r\n", | |
" <link type=\"text/css\" rel=\"Stylesheet\" href=\"//eservice.nlb.gov.sg/components/css/ui-themes.css\" /> \r\n", | |
"\t\r\n", | |
" <!-- Favicons\r\n", | |
" ================================================== -->\r\n", | |
" <link rel=\"shortcut icon\" href=\"//eservice.nlb.gov.sg/components/img/favicon.ico\">\r\n", | |
" <link rel=\"apple-touch-icon\" href=\"//eservice.nlb.gov.sg/components/img/apple-touch-icon.png\">\r\n", | |
" <link rel=\"apple-touch-icon\" sizes=\"72x72\" href=\"//eservice.nlb.gov.sg/components/img/apple-touch-icon-72x72.png\">\r\n", | |
" <link rel=\"apple-touch-icon\" sizes=\"114x114\" href=\"//eservice.nlb.gov.sg/components/img/apple-touch-icon-114x114.png\">\r\n", | |
"\t\r\n", | |
" <!-- JS\r\n", | |
" ================================================== -->\r\n", | |
" <script type=\"text/javascript\" src=\"javascripts/jquery-1.11.0.min.js\"></script>\r\n", | |
" <script type=\"text/javascript\" id=\"bootstrap\" src=\"//eservice.nlb.gov.sg/components/js/bootstrap.min.js\"></script>\r\n", | |
" <script type=\"text/javascript\" id=\"nlb\" src=\"//eservice.nlb.gov.sg/components/js/bundle.js?key=Zrgtn8cP9kAZ\"></script>\r\n", | |
"\r\n", | |
" <!--<script type=\"text/javascript\" src=\"\"></script>-->\r\n", | |
" \r\n", | |
"\t<!-- Social Bookmark -->\r\n", | |
" <!--<script type=\"text/javascript\">\r\n", | |
" var nlb_sb_source = \"BOOKS\";\r\n", | |
" var nlb_sb_url = \"\";\r\n", | |
" var nlb_sb_title = \"\";\r\n", | |
" var nlb_sb_description = \"\";\r\n", | |
" var nlb_sb_image_url = \"<td width='130px'><img class='bookcover img-responsive' src=\"http://eservice.nlb.gov.sg/bookcoverwrapper/cover/9781593274245\" border=\"1\" /></td>\";\r\n", | |
" </script>-->\r\n", | |
"\r\n", | |
" <script type=\"text/javascript\">\r\n", | |
" $.ajax({\r\n", | |
" url: 'getholding.aspx',\r\n", | |
" data: { \"bid\": \"14375145\", \"br\": \"\", \"loc\": \"\" },\r\n", | |
" cache: false,\r\n", | |
" beforeSend: function (d) {\r\n", | |
" $('div#loading').show();\r\n", | |
" },\r\n", | |
" success: function (d) {\r\n", | |
" $('div#holding').html(d);\r\n", | |
" $('div#loading').hide();\r\n", | |
" },\r\n", | |
" error: function(){\r\n", | |
" $('div#holding').html(\"System error encountered. Please contact helpdesk for assistance.\");\r\n", | |
" $('div#loading').hide();\r\n", | |
" }\r\n", | |
" });\r\n", | |
" </script>\r\n", | |
"</head>\r\n", | |
"\r\n", | |
"<body>\r\n", | |
" <div class=\"wrapper\">\r\n", | |
" <!-- Primary Page Layout\r\n", | |
" ================================================== -->\r\n", | |
"\t<div id=\"main-content\" class=\"container\">\r\n", | |
"\t <div> </div>\r\n", | |
"\t\t<div class=\"row\">\r\n", | |
"\t\t <div class=\"col-md-2 col-sm-3\">\r\n", | |
"\t\t <td width='130px'><img class='bookcover img-responsive' src=\"http://eservice.nlb.gov.sg/bookcoverwrapper/cover/9781593274245\" border=\"1\" /></td>\r\n", | |
"\t\t </div>\r\n", | |
"\t\t <div class=\"col-md-10 col-sm-9\">\r\n", | |
"\t\t <h4>Think like a programmer : an introduction to creative problem solving / V. Anton Spraul.</h4>\r\n", | |
"\t\t <div class=\"row\">\r\n", | |
"\t\t <div class=\"col-lg-7 col-md-6\">\r\n", | |
"\t\t <dl class=\"dl-horizontal\">\r\n", | |
" <dt>Author</dt>\r\n", | |
" <dd>Spraul, V. Anton.</dd>\r\n", | |
" <dt>Publisher</dt>\r\n", | |
" <dd></dd>\r\n", | |
" <dt>ISBN</dt>\r\n", | |
" <dd>9781593274245 (pbk)</dd>\r\n", | |
" <dt>Format</dt>\r\n", | |
" <dd>Books</dd>\r\n", | |
" <dt>Physical Description</dt>\r\n", | |
" <dd>xvii, 233 pages :illustrations ;24 cm</dd>\r\n", | |
" <dt>Subjects</dt>\r\n", | |
" <dd>Computer programming<br>\r\n", | |
"Creative thinking<br>\r\n", | |
"Problem solving\r\n", | |
"</dd>\r\n", | |
" </dl>\r\n", | |
" \r\n", | |
"\t\t\t\t <ul>\r\n", | |
" <li><a class='red' href='reservation.aspx?bid=14375145' target='_blank'>Reserve this item</a></li>\r\n", | |
" </ul>\r\n", | |
" </div>\r\n", | |
" <div class=\"col-lg-5 col-md-6 rec-widget\">\r\n", | |
" <div id=\"recommendation-label\">Recommendation</div>\r\n", | |
"\t\t\t\t <script type=\"text/javascript\">\r\n", | |
"\t\t\t\t var bid = '14375145';\r\n", | |
"\t\t\t\t var isbn = '';\r\n", | |
"\t\t\t\t </script>\r\n", | |
"\t\t\t\t <script src=\"http://eservice.nlb.gov.sg/recommendation/inc/recWidget.js\" type=\"text/javascript\"></script> \r\n", | |
" </div>\r\n", | |
" </div>\r\n", | |
" <!--<div class='socialbookmark2'></div>-->\r\n", | |
"\t\t </div>\r\n", | |
"\t\t</div>\r\n", | |
"\t\t\t\t\r\n", | |
"\t <h3>Locations with this item</h3>\t\r\n", | |
" <div id=\"loading\">Loading...</div> \r\n", | |
" <!---->\r\n", | |
" <div id=\"holding\"></div> \r\n", | |
" </div>\r\n", | |
"\t</div>\r\n", | |
"</body>\r\n", | |
"</html>\r\n", | |
"\n" | |
] | |
} | |
], | |
"source": [ | |
"print(details_html)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"\r\n", | |
" \r\n", | |
"<table class=\"table table-bordered table-striped table-list\">\r\n", | |
"<thead class='hidden-xs'><tr><th class='text-right'>No.</th><th class='col-sm-3'>Library</th><th class='col-sm-3'>Location</th><th class='col-sm-3'>Call No</th><th class='col-sm-2'>Status/Desc</th><th class='col-sm-1'>Due Date</th></tr></thead><tbody>\r\n", | |
"<tr>\r\n", | |
"<td class='text-right hidden-xs'>1</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Library: </span>Ang Mo Kio Public Library</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Location: </span>Adult Lending</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Call No: </span>English 005.1 SPR -[COM]</td>\r\n", | |
"<td class='col-sm-2'><span class='visible-xs-inline text-muted'>Status: </span>On Loan</td>\r\n", | |
"<td class='col-sm-1'><span class='visible-xs-inline text-muted'>Due Date: </span>23/08/2018</td>\r\n", | |
"</tr>\r\n", | |
"<tr>\r\n", | |
"<td class='text-right hidden-xs'>2</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Library: </span>Bishan Public Library</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Location: </span>Adult Lending</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Call No: </span>English 005.1 SPR -[COM]</td>\r\n", | |
"<td class='col-sm-2'><span class='visible-xs-inline text-muted'>Status: </span>Not On Loan</td>\r\n", | |
"<td class='col-sm-1'><span class='visible-xs-inline text-muted'>Due Date: </span>-</td>\r\n", | |
"</tr>\r\n", | |
"<tr>\r\n", | |
"<td class='text-right hidden-xs'>3</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Library: </span>Bukit Batok Public Library</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Location: </span>Adult Lending</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Call No: </span>English 005.1 SPR -[COM]</td>\r\n", | |
"<td class='col-sm-2'><span class='visible-xs-inline text-muted'>Status: </span>On Loan</td>\r\n", | |
"<td class='col-sm-1'><span class='visible-xs-inline text-muted'>Due Date: </span>07/08/2018</td>\r\n", | |
"</tr>\r\n", | |
"<tr>\r\n", | |
"<td class='text-right hidden-xs'>4</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Library: </span>Bukit Merah Public Library</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Location: </span>Adult Lending</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Call No: </span>English 005.1 SPR -[COM]</td>\r\n", | |
"<td class='col-sm-2'><span class='visible-xs-inline text-muted'>Status: </span>On Loan</td>\r\n", | |
"<td class='col-sm-1'><span class='visible-xs-inline text-muted'>Due Date: </span>03/08/2018</td>\r\n", | |
"</tr>\r\n", | |
"<tr>\r\n", | |
"<td class='text-right hidden-xs'>5</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Library: </span>Central Public Library</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Location: </span>Adult Lending</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Call No: </span>English 005.1 SPR -[COM]</td>\r\n", | |
"<td class='col-sm-2'><span class='visible-xs-inline text-muted'>Status: </span>Not On Loan</td>\r\n", | |
"<td class='col-sm-1'><span class='visible-xs-inline text-muted'>Due Date: </span>-</td>\r\n", | |
"</tr>\r\n", | |
"<tr>\r\n", | |
"<td class='text-right hidden-xs'>6</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Library: </span>Cheng San Public Library</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Location: </span>Adult Lending</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Call No: </span>English 005.1 SPR -[COM]</td>\r\n", | |
"<td class='col-sm-2'><span class='visible-xs-inline text-muted'>Status: </span>On Loan</td>\r\n", | |
"<td class='col-sm-1'><span class='visible-xs-inline text-muted'>Due Date: </span>31/07/2018</td>\r\n", | |
"</tr>\r\n", | |
"<tr>\r\n", | |
"<td class='text-right hidden-xs'>7</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Library: </span>Choa Chu Kang Public Library</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Location: </span>Adult Lending</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Call No: </span>English 005.1 SPR -[COM]</td>\r\n", | |
"<td class='col-sm-2'><span class='visible-xs-inline text-muted'>Status: </span>On Loan</td>\r\n", | |
"<td class='col-sm-1'><span class='visible-xs-inline text-muted'>Due Date: </span>15/02/2018</td>\r\n", | |
"</tr>\r\n", | |
"<tr>\r\n", | |
"<td class='text-right hidden-xs'>8</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Library: </span>Clementi Public Library</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Location: </span>Adult Lending</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Call No: </span>English 005.1 SPR -[COM]</td>\r\n", | |
"<td class='col-sm-2'><span class='visible-xs-inline text-muted'>Status: </span>Not On Loan</td>\r\n", | |
"<td class='col-sm-1'><span class='visible-xs-inline text-muted'>Due Date: </span>-</td>\r\n", | |
"</tr>\r\n", | |
"<tr>\r\n", | |
"<td class='text-right hidden-xs'>9</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Library: </span>Jurong Regional Library</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Location: </span>Adult Lending</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Call No: </span>English 005.1 SPR -[COM]</td>\r\n", | |
"<td class='col-sm-2'><span class='visible-xs-inline text-muted'>Status: </span>On Loan</td>\r\n", | |
"<td class='col-sm-1'><span class='visible-xs-inline text-muted'>Due Date: </span>15/08/2018</td>\r\n", | |
"</tr>\r\n", | |
"<tr>\r\n", | |
"<td class='text-right hidden-xs'>10</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Library: </span>Jurong West Public Library</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Location: </span>Adult Lending</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Call No: </span>English 005.1 SPR -[COM]</td>\r\n", | |
"<td class='col-sm-2'><span class='visible-xs-inline text-muted'>Status: </span>On Loan</td>\r\n", | |
"<td class='col-sm-1'><span class='visible-xs-inline text-muted'>Due Date: </span>05/08/2018</td>\r\n", | |
"</tr>\r\n", | |
"<tr>\r\n", | |
"<td class='text-right hidden-xs'>11</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Library: </span>Marine Parade Public Library</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Location: </span>Adult Lending</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Call No: </span>English 005.1 SPR -[COM]</td>\r\n", | |
"<td class='col-sm-2'><span class='visible-xs-inline text-muted'>Status: </span>Not On Loan</td>\r\n", | |
"<td class='col-sm-1'><span class='visible-xs-inline text-muted'>Due Date: </span>-</td>\r\n", | |
"</tr>\r\n", | |
"<tr>\r\n", | |
"<td class='text-right hidden-xs'>12</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Library: </span>Pasir Ris Public Library</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Location: </span>Adult Lending</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Call No: </span>English 005.1 SPR -[COM]</td>\r\n", | |
"<td class='col-sm-2'><span class='visible-xs-inline text-muted'>Status: </span>On Loan</td>\r\n", | |
"<td class='col-sm-1'><span class='visible-xs-inline text-muted'>Due Date: </span>17/08/2018</td>\r\n", | |
"</tr>\r\n", | |
"<tr>\r\n", | |
"<td class='text-right hidden-xs'>13</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Library: </span>Queenstown Public Library</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Location: </span>Adult Lending</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Call No: </span>English 005.1 SPR -[COM]</td>\r\n", | |
"<td class='col-sm-2'><span class='visible-xs-inline text-muted'>Status: </span>On Loan</td>\r\n", | |
"<td class='col-sm-1'><span class='visible-xs-inline text-muted'>Due Date: </span>12/08/2018</td>\r\n", | |
"</tr>\r\n", | |
"<tr>\r\n", | |
"<td class='text-right hidden-xs'>14</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Library: </span>Serangoon Public Library</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Location: </span>Adult Lending</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Call No: </span>English 005.1 SPR -[COM]</td>\r\n", | |
"<td class='col-sm-2'><span class='visible-xs-inline text-muted'>Status: </span>On Loan</td>\r\n", | |
"<td class='col-sm-1'><span class='visible-xs-inline text-muted'>Due Date: </span>18/08/2018</td>\r\n", | |
"</tr>\r\n", | |
"<tr>\r\n", | |
"<td class='text-right hidden-xs'>15</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Library: </span>Tampines Regional Library</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Location: </span>Adult Lending</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Call No: </span>English 005.1 SPR -[COM]</td>\r\n", | |
"<td class='col-sm-2'><span class='visible-xs-inline text-muted'>Status: </span>On Loan</td>\r\n", | |
"<td class='col-sm-1'><span class='visible-xs-inline text-muted'>Due Date: </span>26/08/2018</td>\r\n", | |
"</tr>\r\n", | |
"<tr>\r\n", | |
"<td class='text-right hidden-xs'>16</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Library: </span>Woodlands Regional Library</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Location: </span>Adult Lending</td>\r\n", | |
"<td class='col-sm-3'><span class='visible-xs-inline text-muted'>Call No: </span>English 005.1 SPR -[COM]</td>\r\n", | |
"<td class='col-sm-2'><span class='visible-xs-inline text-muted'>Status: </span>On Loan</td>\r\n", | |
"<td class='col-sm-1'><span class='visible-xs-inline text-muted'>Due Date: </span>17/08/2018</td>\r\n", | |
"</tr>\r\n", | |
"</tbody>\r\n", | |
"\r\n", | |
"</table>\r\n", | |
"\n" | |
] | |
} | |
], | |
"source": [ | |
"print(holding_html)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"'Think like a programmer : an introduction to creative problem solving / V. Anton Spraul.'" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"tree = etree.HTML(details_html)\n", | |
"title = tree.xpath('//*[@id=\"main-content\"]/div[2]/div[2]/h4/text()')[0]\n", | |
"\n", | |
"title" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<img src=\"http://eservice.nlb.gov.sg/bookcoverwrapper/cover/9781593274245\"/>" | |
], | |
"text/plain": [ | |
"<IPython.core.display.Image object>" | |
] | |
}, | |
"execution_count": 6, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"from IPython.display import Image\n", | |
"from IPython.core.display import HTML\n", | |
"\n", | |
"cover = tree.xpath('//img[contains(@class, \"bookcover\")]/@src')[0]\n", | |
"Image(url = cover)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'Author': 'Spraul, V. Anton.',\n", | |
" 'Publisher': '9781593274245 (pbk)',\n", | |
" 'ISBN': 'Books',\n", | |
" 'Format': 'xvii, 233 pages :illustrations ;24 cm',\n", | |
" 'Physical Description': 'Computer programming',\n", | |
" 'Subjects': 'Creative thinking'}" | |
] | |
}, | |
"execution_count": 7, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"props = tree.xpath('//*[@id=\"main-content\"]/div[2]/div[2]/div/div[1]/dl/dt/text()')\n", | |
"vals = tree.xpath('//*[@id=\"main-content\"]/div[2]/div[2]/div/div[1]/dl/dd/text()')\n", | |
"{p: str(v).strip() for p, v in zip(props, vals)}" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<div>\n", | |
"<style scoped>\n", | |
" .dataframe tbody tr th:only-of-type {\n", | |
" vertical-align: middle;\n", | |
" }\n", | |
"\n", | |
" .dataframe tbody tr th {\n", | |
" vertical-align: top;\n", | |
" }\n", | |
"\n", | |
" .dataframe thead th {\n", | |
" text-align: right;\n", | |
" }\n", | |
"</style>\n", | |
"<table border=\"1\" class=\"dataframe\">\n", | |
" <thead>\n", | |
" <tr style=\"text-align: right;\">\n", | |
" <th></th>\n", | |
" <th>Library</th>\n", | |
" <th>Location</th>\n", | |
" <th>Call No</th>\n", | |
" <th>Status/Desc</th>\n", | |
" <th>Due Date</th>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>No.</th>\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" <th></th>\n", | |
" </tr>\n", | |
" </thead>\n", | |
" <tbody>\n", | |
" <tr>\n", | |
" <th>1</th>\n", | |
" <td>Library: Ang Mo Kio Public Library</td>\n", | |
" <td>Location: Adult Lending</td>\n", | |
" <td>Call No: English 005.1 SPR -[COM]</td>\n", | |
" <td>Status: On Loan</td>\n", | |
" <td>Due Date: 23/08/2018</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>2</th>\n", | |
" <td>Library: Bishan Public Library</td>\n", | |
" <td>Location: Adult Lending</td>\n", | |
" <td>Call No: English 005.1 SPR -[COM]</td>\n", | |
" <td>Status: Not On Loan</td>\n", | |
" <td>Due Date: -</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>3</th>\n", | |
" <td>Library: Bukit Batok Public Library</td>\n", | |
" <td>Location: Adult Lending</td>\n", | |
" <td>Call No: English 005.1 SPR -[COM]</td>\n", | |
" <td>Status: On Loan</td>\n", | |
" <td>Due Date: 07/08/2018</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>4</th>\n", | |
" <td>Library: Bukit Merah Public Library</td>\n", | |
" <td>Location: Adult Lending</td>\n", | |
" <td>Call No: English 005.1 SPR -[COM]</td>\n", | |
" <td>Status: On Loan</td>\n", | |
" <td>Due Date: 03/08/2018</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>5</th>\n", | |
" <td>Library: Central Public Library</td>\n", | |
" <td>Location: Adult Lending</td>\n", | |
" <td>Call No: English 005.1 SPR -[COM]</td>\n", | |
" <td>Status: Not On Loan</td>\n", | |
" <td>Due Date: -</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>6</th>\n", | |
" <td>Library: Cheng San Public Library</td>\n", | |
" <td>Location: Adult Lending</td>\n", | |
" <td>Call No: English 005.1 SPR -[COM]</td>\n", | |
" <td>Status: On Loan</td>\n", | |
" <td>Due Date: 31/07/2018</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>7</th>\n", | |
" <td>Library: Choa Chu Kang Public Library</td>\n", | |
" <td>Location: Adult Lending</td>\n", | |
" <td>Call No: English 005.1 SPR -[COM]</td>\n", | |
" <td>Status: On Loan</td>\n", | |
" <td>Due Date: 15/02/2018</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>8</th>\n", | |
" <td>Library: Clementi Public Library</td>\n", | |
" <td>Location: Adult Lending</td>\n", | |
" <td>Call No: English 005.1 SPR -[COM]</td>\n", | |
" <td>Status: Not On Loan</td>\n", | |
" <td>Due Date: -</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>9</th>\n", | |
" <td>Library: Jurong Regional Library</td>\n", | |
" <td>Location: Adult Lending</td>\n", | |
" <td>Call No: English 005.1 SPR -[COM]</td>\n", | |
" <td>Status: On Loan</td>\n", | |
" <td>Due Date: 15/08/2018</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>10</th>\n", | |
" <td>Library: Jurong West Public Library</td>\n", | |
" <td>Location: Adult Lending</td>\n", | |
" <td>Call No: English 005.1 SPR -[COM]</td>\n", | |
" <td>Status: On Loan</td>\n", | |
" <td>Due Date: 05/08/2018</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>11</th>\n", | |
" <td>Library: Marine Parade Public Library</td>\n", | |
" <td>Location: Adult Lending</td>\n", | |
" <td>Call No: English 005.1 SPR -[COM]</td>\n", | |
" <td>Status: Not On Loan</td>\n", | |
" <td>Due Date: -</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>12</th>\n", | |
" <td>Library: Pasir Ris Public Library</td>\n", | |
" <td>Location: Adult Lending</td>\n", | |
" <td>Call No: English 005.1 SPR -[COM]</td>\n", | |
" <td>Status: On Loan</td>\n", | |
" <td>Due Date: 17/08/2018</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>13</th>\n", | |
" <td>Library: Queenstown Public Library</td>\n", | |
" <td>Location: Adult Lending</td>\n", | |
" <td>Call No: English 005.1 SPR -[COM]</td>\n", | |
" <td>Status: On Loan</td>\n", | |
" <td>Due Date: 12/08/2018</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>14</th>\n", | |
" <td>Library: Serangoon Public Library</td>\n", | |
" <td>Location: Adult Lending</td>\n", | |
" <td>Call No: English 005.1 SPR -[COM]</td>\n", | |
" <td>Status: On Loan</td>\n", | |
" <td>Due Date: 18/08/2018</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>15</th>\n", | |
" <td>Library: Tampines Regional Library</td>\n", | |
" <td>Location: Adult Lending</td>\n", | |
" <td>Call No: English 005.1 SPR -[COM]</td>\n", | |
" <td>Status: On Loan</td>\n", | |
" <td>Due Date: 26/08/2018</td>\n", | |
" </tr>\n", | |
" <tr>\n", | |
" <th>16</th>\n", | |
" <td>Library: Woodlands Regional Library</td>\n", | |
" <td>Location: Adult Lending</td>\n", | |
" <td>Call No: English 005.1 SPR -[COM]</td>\n", | |
" <td>Status: On Loan</td>\n", | |
" <td>Due Date: 17/08/2018</td>\n", | |
" </tr>\n", | |
" </tbody>\n", | |
"</table>\n", | |
"</div>" | |
], | |
"text/plain": [ | |
" Library Location \\\n", | |
"No. \n", | |
"1 Library: Ang Mo Kio Public Library Location: Adult Lending \n", | |
"2 Library: Bishan Public Library Location: Adult Lending \n", | |
"3 Library: Bukit Batok Public Library Location: Adult Lending \n", | |
"4 Library: Bukit Merah Public Library Location: Adult Lending \n", | |
"5 Library: Central Public Library Location: Adult Lending \n", | |
"6 Library: Cheng San Public Library Location: Adult Lending \n", | |
"7 Library: Choa Chu Kang Public Library Location: Adult Lending \n", | |
"8 Library: Clementi Public Library Location: Adult Lending \n", | |
"9 Library: Jurong Regional Library Location: Adult Lending \n", | |
"10 Library: Jurong West Public Library Location: Adult Lending \n", | |
"11 Library: Marine Parade Public Library Location: Adult Lending \n", | |
"12 Library: Pasir Ris Public Library Location: Adult Lending \n", | |
"13 Library: Queenstown Public Library Location: Adult Lending \n", | |
"14 Library: Serangoon Public Library Location: Adult Lending \n", | |
"15 Library: Tampines Regional Library Location: Adult Lending \n", | |
"16 Library: Woodlands Regional Library Location: Adult Lending \n", | |
"\n", | |
" Call No Status/Desc \\\n", | |
"No. \n", | |
"1 Call No: English 005.1 SPR -[COM] Status: On Loan \n", | |
"2 Call No: English 005.1 SPR -[COM] Status: Not On Loan \n", | |
"3 Call No: English 005.1 SPR -[COM] Status: On Loan \n", | |
"4 Call No: English 005.1 SPR -[COM] Status: On Loan \n", | |
"5 Call No: English 005.1 SPR -[COM] Status: Not On Loan \n", | |
"6 Call No: English 005.1 SPR -[COM] Status: On Loan \n", | |
"7 Call No: English 005.1 SPR -[COM] Status: On Loan \n", | |
"8 Call No: English 005.1 SPR -[COM] Status: Not On Loan \n", | |
"9 Call No: English 005.1 SPR -[COM] Status: On Loan \n", | |
"10 Call No: English 005.1 SPR -[COM] Status: On Loan \n", | |
"11 Call No: English 005.1 SPR -[COM] Status: Not On Loan \n", | |
"12 Call No: English 005.1 SPR -[COM] Status: On Loan \n", | |
"13 Call No: English 005.1 SPR -[COM] Status: On Loan \n", | |
"14 Call No: English 005.1 SPR -[COM] Status: On Loan \n", | |
"15 Call No: English 005.1 SPR -[COM] Status: On Loan \n", | |
"16 Call No: English 005.1 SPR -[COM] Status: On Loan \n", | |
"\n", | |
" Due Date \n", | |
"No. \n", | |
"1 Due Date: 23/08/2018 \n", | |
"2 Due Date: - \n", | |
"3 Due Date: 07/08/2018 \n", | |
"4 Due Date: 03/08/2018 \n", | |
"5 Due Date: - \n", | |
"6 Due Date: 31/07/2018 \n", | |
"7 Due Date: 15/02/2018 \n", | |
"8 Due Date: - \n", | |
"9 Due Date: 15/08/2018 \n", | |
"10 Due Date: 05/08/2018 \n", | |
"11 Due Date: - \n", | |
"12 Due Date: 17/08/2018 \n", | |
"13 Due Date: 12/08/2018 \n", | |
"14 Due Date: 18/08/2018 \n", | |
"15 Due Date: 26/08/2018 \n", | |
"16 Due Date: 17/08/2018 " | |
] | |
}, | |
"execution_count": 8, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"holding = pd.read_html(holding_html, header=0, index_col=0)[0]\n", | |
"holding" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": {}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3", | |
"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.6.0" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment