Giter VIP home page Giter VIP logo

api-scraping-demo's Introduction

APIs and scraping example

This was a live coded demo of how to use APIs and how to scrape a website

APIs

An API stands for Application Programming Interface. However for the web if often means a way to get back data in structured format, usually JSON.

For the API demo we looked at this list of APIs and chose the MetaWeather API. We created api-test.js which fetched the woeid for three cities and then used that to query the API to get the weather for those locations.

node api-test.js

Async JS

We talked about asyncronous JavaScript and so I made a quick demo in async.js which shows different ways of using JavaScript to perform asyncronous tasks. For the scraping demo I tried to keep things simple by using the syncronous APIs.

Scraping

For the scraping we use the Royal Academy's Summer Exhibition website to look at how the size of a painting effects its price.

How to run

We generate a list of urls and use wget to download them

node gen-urls.js > urls.txt
mkdir raw
cd raw
wget -i ../urls.txt 
cd ..

Wait for the urls to download. Then we use scrape-work-urls.js to create card-urls.txt a list of urls for each individual work. We also create data.csv which has title,href,price for each work.

node scrape-work-urls.js
mkdir raw_artworks
cd raw_artworks
wget -i ../card-urls.txt
cd ..

We then wrote scrape-work-dimensions.js to go over each card page we downloaded and extract out the width and height, and then join that data back to data.csv and we wrote out data2.csv which has all the info we need.

node scrape-work-dimensions.js

price by height x width

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.