Skip to content

Instantly share code, notes, and snippets.

@jminas
Last active August 26, 2016 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jminas/99cd8c887ae5b7d969549ace623ffb85 to your computer and use it in GitHub Desktop.
Save jminas/99cd8c887ae5b7d969549ace623ffb85 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 65,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Populating the interactive namespace from numpy and matplotlib\n"
]
},
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>date</th>\n",
" <th>retailer</th>\n",
" <th>units_sold</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
"Empty DataFrame\n",
"Columns: [date, retailer, units_sold]\n",
"Index: []"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import time\n",
"today = time.strftime(\"%Y-%m-%d %H:%M\")\n",
"import pandas as pd\n",
"import numpy as np\n",
"%pylab inline\n",
"df = pd.DataFrame({'retailer' : [], 'date' : [], 'units_sold': []})\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'bs4.BeautifulSoup'>\n"
]
}
],
"source": [
"from bs4 import BeautifulSoup\n",
"import urllib\n",
"r = urllib.urlopen('http://www.readymaderc.com/store/index.php?main_page=product_info&cPath=505_778_779&products_id=5763').read()\n",
"soup = BeautifulSoup(r)\n",
"print type(soup)"
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<iframe src=http://www.readymaderc.com/store/index.php?main_page=product_info&cPath=505_778_779&products_id=5763 width=700 height=500></iframe>"
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from IPython.display import HTML\n",
"HTML('<iframe src=http://www.readymaderc.com/store/index.php?main_page=product_info&cPath=505_778_779&products_id=5763 width=700 height=500></iframe>')"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>date</th>\n",
" <th>retailer</th>\n",
" <th>units_sold</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2016-08-26 10:45</td>\n",
" <td>readymaderc</td>\n",
" <td>96</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" date retailer units_sold\n",
"0 2016-08-26 10:45 readymaderc 96"
]
},
"execution_count": 74,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"unit = soup.find_all(\"ul\", id=\"productDetailsList\")[0]\n",
"\n",
"#letters = soup.find_all(\"div\", class_=\"ec_statements\")\n",
"#soup.findAll(\"ul\" )\n",
"rmrc = unit.getText().split(\"\\n\")[-2].split()[0]\n",
"rmrc_df = pd.DataFrame({'retailer' : ['readymaderc'], 'date' : [today], 'units_sold': [rmrc]})\n",
"rmrc_df"
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>date</th>\n",
" <th>retailer</th>\n",
" <th>units_sold</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>2016-08-26 10:45</td>\n",
" <td>readymaderc</td>\n",
" <td>96</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2016-08-26 10:45</td>\n",
" <td>readymaderc</td>\n",
" <td>96</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" date retailer units_sold\n",
"0 2016-08-26 10:45 readymaderc 96\n",
"1 2016-08-26 10:45 readymaderc 96"
]
},
"execution_count": 75,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#appending it to master df\n",
"df = df.append(rmrc_df, ignore_index=True)\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.12"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment