Created
February 21, 2019 16:19
-
-
Save jrjames83/cf5ba310dfed26d2fcc6d18186f03584 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": 14, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import requests\n", | |
| "from bs4 import BeautifulSoup\n", | |
| "import re" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "<Response [200]>" | |
| ] | |
| }, | |
| "execution_count": 2, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "resp = requests.get('https://denver.craigslist.org/search/ata')\n", | |
| "resp" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 3, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "soup = BeautifulSoup(resp.content, \"html.parser\")" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "120" | |
| ] | |
| }, | |
| "execution_count": 4, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "items = soup.find_all('li', {\"class\": \"result-row\"})\n", | |
| "len(items)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 20, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "def extract_from_item_div(soup_object):\n", | |
| " name = soup_object.find_all('a')[1].get_text() # possibly hacky?\n", | |
| " try:\n", | |
| " # since not all items have a price, anticiate the exception and just base variable setting\n", | |
| " # on the occurrence of the exception\n", | |
| " price = soup_object.find('span', {'class': 'result-price'}).get_text()\n", | |
| " except:\n", | |
| " price = None\n", | |
| " return (name, price)\n", | |
| " " | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 21, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "('Ore Cart made in Denver', None)\n", | |
| "('Small Handmade Wall Cupboard - Solid wood - SO CUTE / VERY well-made!', '$45')\n", | |
| "('Vintage Street Signs From Leadville, Colorado', '$95')\n", | |
| "('Vintage Cubist Fosteria Glass Set', '$20')\n", | |
| "('Old Schlitz sign (reduced)', '$25')\n", | |
| "('Vintage Signed Anchor Hocking Light Blue Dessert Dishes', '$40')\n", | |
| "('Vintage Metal Milk Bottle Carrier', '$20')\n", | |
| "('Mid-century Westinghouse warmer/ cooker', '$45')\n", | |
| "('Twin carved beds', '$385')\n", | |
| "('Antique Window 6 Pane', '$25')\n", | |
| "('ANTIQUE 1919 WESTERN ELECTRIC CRANK PHONE GRATE SHAPE', '$225')\n", | |
| "('Philco Radio Phonograph player', '$65')\n", | |
| "('Antique U.S. 1943 Bishops Binoculars With Case', '$40')\n", | |
| "('Beautiful antique twin beds', '$325')\n", | |
| "('Replica Nonfiring (plugged) Colt 45', '$125')\n", | |
| "('Antique Girls bedroom Set', '$800')\n", | |
| "('2 Vintage Metal Carnival Horse 8 x 11 1/2 Inches in Size', '$50')\n", | |
| "('ANTIQUE / VINTAGE STAINED GLASS PANEL BLUE IRIS', '$80')\n", | |
| "('WESTERN OIL PAINTINGS * PRINTS ETC', None)\n", | |
| "('Stunning Antique Gothic Revival Oak Hall Chairs - Set Of 4', '$450')\n", | |
| "('Stunning Vintage Hand Carved Wood Thorn Chair', '$1350')\n", | |
| "('Antique Necchi all original sewing machine', '$60')\n", | |
| "('Vintage Funeral Home Register Stand', '$200')\n", | |
| "('Vanity 1930s', '$60')\n", | |
| "('Crystal Boudoir Lamp', '$45')\n", | |
| "('Cuckoo Clock(Reduced)', '$200')\n", | |
| "('Set of 4 Glass teabag holders, vintage', '$10')\n", | |
| "('Vintage South American Bark Dolls', '$10')\n", | |
| "('Vintage Royal Haeger Ceramic Horse', '$15')\n", | |
| "('Pink Depression Glass', '$35')\n", | |
| "('Various Vintage Blue Glass Pieces', None)\n", | |
| "('Vintage Oneida Morning Star Flatware', '$65')\n", | |
| "('Vintage Levington Milk Glass Lamp', '$25')\n", | |
| "(\"1960's Golden Peony Porcelain Plate\", '$15')\n", | |
| "('Vintage Blue/White & Delft China Pieces', None)\n", | |
| "('Vintage Etched Blue Glass Decanter and Cordial Glasses', '$50')\n", | |
| "('Vintage Olympia De Luxe Typewriter', '$100')\n", | |
| "('Vintage Bake, Serve, and Store Stoneware', '$30')\n", | |
| "(\"1940's Fransiscan Ware Dessert Rose Teapot\", '$25')\n", | |
| "('Federal Glass Plates and Bowls', '$35')\n", | |
| "('Effanbee Baby Doll', '$70')\n", | |
| "('Antique Mahogany Envelope Table', '$150')\n", | |
| "('Antique Blue Cloisonne Lamp', '$35')\n", | |
| "('Vintage Etched Glasses', '$25')\n", | |
| "('Vintage Carnival Glass Leaf Dish', '$15')\n", | |
| "('Near Antique China set, Pre-Occupied Japan', '$300')\n", | |
| "('Vintage Ice Blue Glass Appetizer Plate and Bowl', '$25')\n", | |
| "('Drexel vintage solid mahogany media/buffet cabinet', '$150')\n", | |
| "(\"Shawnee Teapot, Tom the Piper's Son\", '$40')\n", | |
| "('Various Vintage Colored Glass Pieces', None)\n", | |
| "('Silverplatted footed bowl and platter', '$15')\n", | |
| "('Vintage Green Glass Perfume Bottle', '$25')\n", | |
| "('New and Vintage Tablecloths and Napkins', None)\n", | |
| "('Vintage Pair Log Cabin Glass Bottles', '$15')\n", | |
| "('Vintage Lennox China', None)\n", | |
| "('Vintage Hazel Atlas Orchard Snack Set', '$25')\n", | |
| "('Vintage Octagon Centerpiece Bowl', '$15')\n", | |
| "('Vintage Silver on Copper Tea Set', '$65')\n", | |
| "('4 set vintage sandwich pattern plates', '$10')\n", | |
| "(\"Antique children's rocking chair\", '$25')\n", | |
| "(\"Antique children's rocking chair\", '$25')\n", | |
| "('PICHER/DRINKING GLASSES', '$1')\n", | |
| "('Vintage Amber Glass Candy Dish', '$20')\n", | |
| "('ASBESTOS SAD IRON', '$1')\n", | |
| "('VINTAGE LANTERN', '$40')\n", | |
| "('Vintage Strawberry Covered 3 Sections Condiment Dish -Fred Roberts', '$10')\n", | |
| "('Vintage Silver Plated Footed Pitcher And Tray', '$50')\n", | |
| "('Vintage Reichenbacher Fine China Vase', '$15')\n", | |
| "('F.B.Rogers & CO. Silver plated Candy Dish', '$15')\n", | |
| "('ICE BLUE CANDY DISH', '$10')\n", | |
| "('Vintage Silver Plated Appetizer Bowl', '$15')\n", | |
| "('Antique & Vintage Lamps', None)\n", | |
| "('Pair Vintage Divided Colored Glass Dishes', '$15')\n", | |
| "('Vintage Hand Painted Spanish Dish', '$10')\n", | |
| "(\"Vintage Kelvin's porcelain figurine\", '$15')\n", | |
| "('Vintage Norman Rockwell Prints', '$10')\n", | |
| "('Vintage Corning Ware Set', '$75')\n", | |
| "('Various Vintage/Antique Glass', None)\n", | |
| "('Vintage Viking Glass Lotus Blossom Bowl', '$15')\n", | |
| "('Various Milk Glass Pieces', None)\n", | |
| "('Antique Victorian Silver Plated Butter Dish', '$20')\n", | |
| "('Pair Vintage Glass Perfume Bottles, French', '$10')\n", | |
| "('Mid Century Signed Anchor Hockings Blue Glass Dessert Dishes', '$40')\n", | |
| "('Various Silver Plated Dining Items', None)\n", | |
| "('Vintage Green Glass Perfume Bottle', '$25')\n", | |
| "('Orrefero Rhapsody Crystal Glass Set', '$165')\n", | |
| "('Various China Plates', '$10')\n", | |
| "('Vintage Edwin Knowles Forsythia Dishes', '$15')\n", | |
| "('Midcentury McCoy Apple Cookie Jar', '$15')\n", | |
| "('Vintage Green Indiana Glass Snack Plate Sets (Thumbprint/Kings Crown)', '$35')\n", | |
| "('Vintage Brass Dual Bulb Table Lamp', '$30')\n", | |
| "('Incredible Holy Land Collection!', '$100000')\n", | |
| "('Antique Curio Cabinet', '$75')\n", | |
| "(\"Blueboy Print from the Late 20's or Early 30's\", '$50')\n", | |
| "('Anitique Singer Sewing Machines and Windsor and Royal Sewing Machine', '$1')\n", | |
| "('HALL TREE, HONEY OAK', '$110')\n", | |
| "('Horse Drawn Yard Ornament & Antiques', '$550')\n", | |
| "('Vintage 1950s 3-D View-Master Model E with 25 Reels', '$300')\n", | |
| "('Rare Motorola 57H Tube Radio', '$770')\n", | |
| "('1st Edition The Story of Sir Lancelot and His Companions', '$85')\n", | |
| "('Lovely Vintage Black Side Table', '$109')\n", | |
| "('Hand Carved Swedish Wooden Toys for Sale', '$60')\n", | |
| "('Vintage Van Briggle ashtrays', '$75')\n", | |
| "(\"Vintage Retro Orange Barber's Chair w/Foot Pedal Adjustable Height\", '$279')\n", | |
| "('Large Oval Wall Mirror', '$98')\n", | |
| "('Vintage Colored Glass Flowers', '$30')\n", | |
| "('Vintage/Antique Bisque Porcelain Figurine From Italy', '$50')\n", | |
| "('Vintage Gold Frame Mirror', '$95')\n", | |
| "('Samsung Galaxy S8 Active 64GB', '$145')\n", | |
| "('Selling Cute Feet Pictures', None)\n", | |
| "('Vintage ceiling light fixture', '$55')\n", | |
| "('Brass Chandler prior 1950', '$250')\n", | |
| "('Control Boxes starting at $100', '$100')\n", | |
| "('\"Laura by narumi Japan \"', '$75')\n", | |
| "('Small Vintage Coffee/Side Table - Marquetry Top', '$65')\n", | |
| "('REDUCED Mid Century Credenza', '$325')\n", | |
| "('Mid Century Broyhill Brasilia Room Divider', '$1250')\n", | |
| "('Boho Wicker and Rattan Chairs and Headboard', '$200')\n", | |
| "('Mid Century Herman Miller Shell Chair', '$79')\n", | |
| "('REDUCED Vintage Mid Century Egon Ostergaard Roll Top Desk or Bar', '$300')\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "for i in items:\n", | |
| " print(extract_from_item_div(i))" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "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.7" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment