summaryrefslogtreecommitdiff
path: root/megapixels/notebooks/bs4_scratch.ipynb
blob: e63d286f36e454a4a48bf3af12ab285d5a8778b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [],
   "source": [
    "from bs4 import BeautifulSoup\n",
    "from pathlib import Path\n",
    "from os.path import join"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = \"\"\"\n",
    "<div class=\"entry-content\">\n",
    "<h2 id=\"annotations\" class=\"offset\">Annotations</h2>\n",
    "<p>Below are examples of our different annotations within the dataset. Every pedestrian, cyclist and motorcyclist (higher than 50px) in every frame is annotated with a bounding box, along side with three attributes: occlusion, difficult (low contrast or unusual posture) and pose. People on posters, sculptures and groups where individuals are hard to seperate are marked as “ignore”.</p>\n",
    "<style type=\"text/css\">\n",
    "\t\t\t#gallery-3 {\n",
    "\t\t\t\tmargin: auto;\n",
    "\t\t\t}\n",
    "\t\t\t#gallery-3 .gallery-item {\n",
    "\t\t\t\tfloat: left;\n",
    "\t\t\t\tmargin-top: 10px;\n",
    "\t\t\t\ttext-align: center;\n",
    "\t\t\t\twidth: 25%;\n",
    "\t\t\t}\n",
    "\t\t\t#gallery-3 img {\n",
    "\t\t\t\tborder: 2px solid #cfcfcf;\n",
    "\t\t\t}\n",
    "\t\t\t#gallery-3 .gallery-caption {\n",
    "\t\t\t\tmargin-left: 0;\n",
    "\t\t\t}\n",
    "\t\t\t/* see gallery_shortcode() in wp-includes/media.php */\n",
    "\t\t</style>\n",
    "<h2 id=\"pedestrian\" class=\"offset\">Pedestrian</h2>\n",
    "<div id=\"gallery-3\" class=\"gallery galleryid-56 gallery-columns-4 gallery-size-medium\">\n",
    "<dl class=\"gallery-item\">\n",
    "<dt class=\"gallery-icon landscape\">\n",
    "<p>\t\t\t\t<a class=\"grouped_elements\" rel=\"tc-fancybox-group\" href=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/many_peds3.png\" data-lb-type=\"grouped-post\"><img src=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/many_peds3.png\" alt=\"\" class=\"alignnone size-medium wp-image-43\" width=\"300\" height=\"184\"></a>\n",
    "\t\t\t</p></dt>\n",
    "<dd class=\"wp-caption-text gallery-caption\" id=\"gallery-3-81\">\n",
    "\t\t\t\tHigh frequency of pedestrians\n",
    "\t\t\t\t</dd>\n",
    "</dl>\n",
    "<dl class=\"gallery-item\">\n",
    "<dt class=\"gallery-icon landscape\">\n",
    "<p>\t\t\t\t<a class=\"grouped_elements\" rel=\"tc-fancybox-group\" href=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ped_dark_low_contrast.png\" data-lb-type=\"grouped-post\"><img src=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ped_dark_low_contrast.png\" alt=\"\" class=\"alignnone size-medium wp-image-28\" width=\"300\" height=\"186\"></a>\n",
    "\t\t\t</p></dt>\n",
    "<dd class=\"wp-caption-text gallery-caption\" id=\"gallery-3-82\">\n",
    "\t\t\t\tDark scenes with low contrast\n",
    "\t\t\t\t</dd>\n",
    "</dl>\n",
    "<dl class=\"gallery-item\">\n",
    "<dt class=\"gallery-icon landscape\">\n",
    "<p>\t\t\t\t<a class=\"grouped_elements\" rel=\"tc-fancybox-group\" href=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/peds_occluded.png\" data-lb-type=\"grouped-post\"><img src=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/peds_occluded.png\" alt=\"\" class=\"alignnone size-medium wp-image-44\" width=\"300\" height=\"193\"></a>\n",
    "\t\t\t</p></dt>\n",
    "<dd class=\"wp-caption-text gallery-caption\" id=\"gallery-3-83\">\n",
    "\t\t\t\tOccluded pedestrians\n",
    "\t\t\t\t</dd>\n",
    "</dl>\n",
    "<dl class=\"gallery-item\">\n",
    "<dt class=\"gallery-icon landscape\">\n",
    "<p>\t\t\t\t<a class=\"grouped_elements\" rel=\"tc-fancybox-group\" href=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ped_sideways.png\" data-lb-type=\"grouped-post\"><img src=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ped_sideways.png\" alt=\"\" class=\"alignnone size-medium wp-image-44\" width=\"300\" height=\"193\"></a>\n",
    "\t\t\t</p></dt>\n",
    "<dd class=\"wp-caption-text gallery-caption\" id=\"gallery-3-85\">\n",
    "\t\t\t\tSideview of crossing pedestrians\n",
    "\t\t\t\t</dd>\n",
    "</dl>\n",
    "<p><br style=\"clear: both\">\n",
    "\t\t</p></div>\n",
    "<h2 id=\"bicycle\" class=\"offset\">Bicycledriver and Motorbikedriver</h2>\n",
    "<div id=\"gallery-3\" class=\"gallery galleryid-56 gallery-columns-4 gallery-size-medium\">\n",
    "<dl class=\"gallery-item\">\n",
    "<dt class=\"gallery-icon landscape\">\n",
    "\t\t\t\t\t\t\t\t<a class=\"grouped_elements\" rel=\"tc-fancybox-group\" href=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/bicycle_back_glare.png\" data-lb-type=\"grouped-post\"><img src=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/bicycle_back_glare.png\" alt=\"\" class=\"alignnone size-medium wp-image-43\" width=\"300\" height=\"184\"></a>\n",
    "\t\t\t</dt>\n",
    "<dd class=\"wp-caption-text gallery-caption\" id=\"gallery-3-86\">\n",
    "\t\t\t\tBicycle drivers from back including glare\n",
    "\t\t\t\t</dd>\n",
    "</dl>\n",
    "<dl class=\"gallery-item\">\n",
    "<dt class=\"gallery-icon landscape\">\n",
    "<p>\t\t\t\t<a class=\"grouped_elements\" rel=\"tc-fancybox-group\" href=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/bicycle_driver_sideways.png\" data-lb-type=\"grouped-post\"><img src=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/bicycle_driver_sideways.png\" alt=\"\" class=\"alignnone size-medium wp-image-28\" width=\"300\" height=\"186\"></a>\n",
    "\t\t\t</p></dt>\n",
    "<dd class=\"wp-caption-text gallery-caption\" id=\"gallery-3-87\">\n",
    "\t\t\t\tBicycledriver sideways\n",
    "\t\t\t\t</dd>\n",
    "</dl>\n",
    "<dl class=\"gallery-item\">\n",
    "<dt class=\"gallery-icon landscape\">\n",
    "<p>\t\t\t\t<a class=\"grouped_elements\" rel=\"tc-fancybox-group\" href=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/bicycle_mixed_with_ped.png\" data-lb-type=\"grouped-post\"><img src=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/bicycle_mixed_with_ped.png\" alt=\"\" class=\"alignnone size-medium wp-image-44\" width=\"300\" height=\"193\"></a>\n",
    "\t\t\t</p></dt>\n",
    "<dd class=\"wp-caption-text gallery-caption\" id=\"gallery-3-88\">\n",
    "\t\t\t\tScenes with mixed annotations\n",
    "\t\t\t\t</dd>\n",
    "</dl>\n",
    "<dl class=\"gallery-item\">\n",
    "<dt class=\"gallery-icon landscape\">\n",
    "<p>\t\t\t\t<a class=\"grouped_elements\" rel=\"tc-fancybox-group\" href=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/bicycle_multiple_drivers2.png\" data-lb-type=\"grouped-post\"><img src=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/bicycle_multiple_drivers2.png\" alt=\"\" class=\"alignnone size-medium wp-image-44\" width=\"300\" height=\"193\"></a>\n",
    "\t\t\t</p></dt>\n",
    "<dd class=\"wp-caption-text gallery-caption\" id=\"gallery-3-89\">\n",
    "\t\t\t\tMultiple bicycle drivers\n",
    "\t\t\t\t</dd>\n",
    "</dl>\n",
    "<p><br style=\"clear: both\">\n",
    "\t\t</p></div>\n",
    "<div id=\"gallery-3\" class=\"gallery galleryid-56 gallery-columns-4 gallery-size-medium\">\n",
    "<dl class=\"gallery-item\">\n",
    "<dt class=\"gallery-icon landscape\">\n",
    "\t\t\t\t\t\t\t\t<a class=\"grouped_elements\" rel=\"tc-fancybox-group\" href=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/mb_driver_back.png\" data-lb-type=\"grouped-post\"><img src=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/mb_driver_back.png\" alt=\"\" class=\"alignnone size-medium wp-image-43\" width=\"300\" height=\"184\"></a>\n",
    "\t\t\t</dt>\n",
    "<dd class=\"wp-caption-text gallery-caption\" id=\"gallery-3-90\">\n",
    "\t\t\t\tMotorbikedrivers from back\n",
    "\t\t\t\t</dd>\n",
    "</dl>\n",
    "<dl class=\"gallery-item\">\n",
    "<dt class=\"gallery-icon landscape\">\n",
    "<p>\t\t\t\t<a class=\"grouped_elements\" rel=\"tc-fancybox-group\" href=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/mb_drivers_crossing.png\" data-lb-type=\"grouped-post\"><img src=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/mb_drivers_crossing.png\" alt=\"\" class=\"alignnone size-medium wp-image-28\" width=\"300\" height=\"186\"></a>\n",
    "\t\t\t</p></dt>\n",
    "<dd class=\"wp-caption-text gallery-caption\" id=\"gallery-3-91\">\n",
    "\t\t\t\tMultiple motorbikedrives in a scene\n",
    "\t\t\t\t</dd>\n",
    "</dl>\n",
    "<dl class=\"gallery-item\">\n",
    "<dt class=\"gallery-icon landscape\">\n",
    "<p>\t\t\t\t<a class=\"grouped_elements\" rel=\"tc-fancybox-group\" href=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/mb_driver_traffic_glare.png\" data-lb-type=\"grouped-post\"><img src=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/mb_driver_traffic_glare.png\" alt=\"\" class=\"alignnone size-medium wp-image-44\" width=\"300\" height=\"193\"></a>\n",
    "\t\t\t</p></dt>\n",
    "<dd class=\"wp-caption-text gallery-caption\" id=\"gallery-3-92\">\n",
    "\t\t\t\tMotorbikedrivers in traffic including glare\n",
    "\t\t\t\t</dd>\n",
    "</dl>\n",
    "<dl class=\"gallery-item\">\n",
    "<dt class=\"gallery-icon landscape\">\n",
    "<p>\t\t\t\t<a class=\"grouped_elements\" rel=\"tc-fancybox-group\" href=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/mb_driver_back2.png\" data-lb-type=\"grouped-post\"><img src=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/mb_driver_back2.png\" alt=\"\" class=\"alignnone size-medium wp-image-44\" width=\"300\" height=\"193\"></a>\n",
    "\t\t\t</p></dt>\n",
    "<dd class=\"wp-caption-text gallery-caption\" id=\"gallery-3-93\">\n",
    "\t\t\t\tMotorbike driver followed during several frames\n",
    "\t\t\t\t</dd>\n",
    "</dl>\n",
    "<p><br style=\"clear: both\">\n",
    "\t\t</p></div>\n",
    "<h2 id=\"ignore\" class=\"offset\">Ignore</h2>\n",
    "<div id=\"gallery-3\" class=\"gallery galleryid-56 gallery-columns-4 gallery-size-medium\">\n",
    "<dl class=\"gallery-item\">\n",
    "<dt class=\"gallery-icon landscape\">\n",
    "\t\t\t\t\t\t\t\t<a class=\"grouped_elements\" rel=\"tc-fancybox-group\" href=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ignore_group.png\" data-lb-type=\"grouped-post\"><img src=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ignore_group.png\" alt=\"\" class=\"alignnone size-medium wp-image-43\" width=\"300\" height=\"184\"></a>\n",
    "\t\t\t</dt>\n",
    "<dd class=\"wp-caption-text gallery-caption\" id=\"gallery-3-94\">\n",
    "\t\t\t\tIgnore larger group of pedestrians that can not be distinguished\n",
    "\t\t\t\t</dd>\n",
    "</dl>\n",
    "<dl class=\"gallery-item\">\n",
    "<dt class=\"gallery-icon landscape\">\n",
    "<p>\t\t\t\t<a class=\"grouped_elements\" rel=\"tc-fancybox-group\" href=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ign_traffic_signs.png\" data-lb-type=\"grouped-post\"><img src=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ign_traffic_signs.png\" alt=\"\" class=\"alignnone size-medium wp-image-28\" width=\"300\" height=\"186\"></a>\n",
    "\t\t\t</p></dt>\n",
    "<dd class=\"wp-caption-text gallery-caption\" id=\"gallery-3-95\">\n",
    "\t\t\t\tIgnore confusing traffic signs\n",
    "\t\t\t\t</dd>\n",
    "</dl>\n",
    "<dl class=\"gallery-item\">\n",
    "<dt class=\"gallery-icon landscape\">\n",
    "<p>\t\t\t\t<a class=\"grouped_elements\" rel=\"tc-fancybox-group\" href=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ign_passengers.png\" data-lb-type=\"grouped-post\"><img src=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ign_passengers.png\" alt=\"\" class=\"alignnone size-medium wp-image-44\" width=\"300\" height=\"193\"></a>\n",
    "\t\t\t</p></dt>\n",
    "<dd class=\"wp-caption-text gallery-caption\" id=\"gallery-3-96\">\n",
    "\t\t\t\tIgnore irrelevant people like passenger\n",
    "\t\t\t\t</dd>\n",
    "</dl>\n",
    "<dl class=\"gallery-item\">\n",
    "<dt class=\"gallery-icon landscape\">\n",
    "<p>\t\t\t\t<a class=\"grouped_elements\" rel=\"tc-fancybox-group\" href=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ign.ads_.png\" data-lb-type=\"grouped-post\"><img src=\"http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ign.ads_.png\" alt=\"\" class=\"alignnone size-medium wp-image-44\" width=\"300\" height=\"193\"></a>\n",
    "\t\t\t</p></dt>\n",
    "<dd class=\"wp-caption-text gallery-caption\" id=\"gallery-3-97\">\n",
    "\t\t\t\tIgnore advertisements and billboards that may include target objects\n",
    "\t\t\t\t</dd>\n",
    "</dl>\n",
    "<p><br style=\"clear: both\">\n",
    "\t\t</p></div>\n",
    "<p>&nbsp;</p>\n",
    "</div>\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [],
   "source": [
    "def parse_urls(url, exts):\n",
    "  ahrefs = soup.find_all('img')\n",
    "  urls = []\n",
    "  for a in ahrefs:\n",
    "    href = a['href']\n",
    "    if Path(href).suffix[1:] in exts:\n",
    "      urls.append('{}{}'.format(url, href))\n",
    "  return urls\n",
    "\n",
    "def parse_images(url, exts):\n",
    "  imgs = soup.find_all('img')\n",
    "  tags = []\n",
    "  for img in imgs:\n",
    "    src = img['src']\n",
    "    if Path(src).suffix[1:] in exts:\n",
    "      tags.append('{}{}'.format(url, src))\n",
    "  return tags"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "http://www.nightowls-dataset.org/wp-content/uploads/2018/03/many_peds3.png\n",
      "http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ped_dark_low_contrast.png\n",
      "http://www.nightowls-dataset.org/wp-content/uploads/2018/03/peds_occluded.png\n",
      "http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ped_sideways.png\n",
      "http://www.nightowls-dataset.org/wp-content/uploads/2018/03/bicycle_back_glare.png\n",
      "http://www.nightowls-dataset.org/wp-content/uploads/2018/03/bicycle_driver_sideways.png\n",
      "http://www.nightowls-dataset.org/wp-content/uploads/2018/03/bicycle_mixed_with_ped.png\n",
      "http://www.nightowls-dataset.org/wp-content/uploads/2018/03/bicycle_multiple_drivers2.png\n",
      "http://www.nightowls-dataset.org/wp-content/uploads/2018/03/mb_driver_back.png\n",
      "http://www.nightowls-dataset.org/wp-content/uploads/2018/03/mb_drivers_crossing.png\n",
      "http://www.nightowls-dataset.org/wp-content/uploads/2018/03/mb_driver_traffic_glare.png\n",
      "http://www.nightowls-dataset.org/wp-content/uploads/2018/03/mb_driver_back2.png\n",
      "http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ignore_group.png\n",
      "http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ign_traffic_signs.png\n",
      "http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ign_passengers.png\n",
      "http://www.nightowls-dataset.org/wp-content/uploads/2018/03/ign.ads_.png\n"
     ]
    }
   ],
   "source": [
    "soup = BeautifulSoup(data,'lxml')\n",
    "#burl = 'http://skuld.cs.umass.edu/traces/mmsys/2015/paper-5/devset/'\n",
    "burl = ''\n",
    "#tags = parse_urls(burl, ['jpg', 'txt'])\n",
    "tags = parse_images(burl, ['jpg', 'png', 'gif'])\n",
    "for t in tags:\n",
    "  print(t)\n",
    "\n",
    "# for row in rows:\n",
    "#   ahrefs = row.find_all(href=True)\n",
    "#   for a in ahrefs:\n",
    "#     href = a['href']\n",
    "#     if 'zip' in href:\n",
    "#       url = 'http://{}'.format(Path(join(url_root, Path(href).name)))\n",
    "#       print(url)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:megapixels]",
   "language": "python",
   "name": "conda-env-megapixels-py"
  },
  "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.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}