GithubHelp home page GithubHelp logo

robbywashere-zz / jam-api Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dinubs/jam-api

0.0 0.0 0.0 5.23 MB

Parse web pages using CSS query selectors

Home Page: http://www.jamapi.xyz

License: Other

JavaScript 42.44% CSS 13.73% HTML 43.83%

jam-api's Introduction

Jam API

Jam API is a service that allows you to turn any site into a JSON accessible api using CSS selectors. To get started simply run a post request to http://www.jamapi.xyz with formdata of "url" and "json_data", here's an example of what your data should look like:

{
  "title": "title",
  "logo": ".nav-logo img",
  "paragraphs": [{ "elem": ".home-post h1", "value": "text"}], 
  "links": [{"elem": ".home-post > a:first-of-type", "location": "href"}]
}

Using API you can simply generate JSON data from any website.

Code samples

nodejs

const request = require('request');
request.post('http://www.jamapi.xyz/', {form: {url: 'http://www.radcircle.com', json_data: '{"title": "title"}'}}, function(err, response, body) {
  console.log(body); // Return the title from http://www.radcircle.com
})  

Javascript

fetch('http://www.jamapi.xyz', {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      url: 'http://www.radcircle.com',
      json_data: '{"title": "title"}'
    })
  }).then(function(response) {
    return response.json();
  }).then(function(json) {
    document.body.innerHTML = json;
  });  

Ruby

require 'httparty'
response = HTTParty.post("http://www.jamapi.xyz/",
  :body => { "url" => "http://www.radcircle.com", "json_data" => "{'title': 'title'}"})  
puts response.to_json

Features

Will auto pull the img src on corresponding elements, will auto pull the href from links. If passing JSON, you must provide a "elem" property, and then the element attributes you want. When you pass an array with JSON you'll get a structure that looks as follows:

[
  {
      "index": 0,
      "value": {
          "value": "Porter Robinson – Sad Machine (Cosmo’s Midnight Remix)"
      }
  },
  {
      "index": 1,
      "value": {
          "value": "Listen to Rachel Platten’s “Stand By You”"
      }
  }]

All the attributes you provide as JSON will be put inside of the value property, and the index property is to be able to track what index it ocurred in the DOM. I nested JSON values into it's own so that you can still have an "index" property returned and not run into issues.

How it works

Main power of the program is in services/html_to_json.js. Start site with node index after doing npm install.

Suggested node version is at least 4.2.2

jam-api's People

Contributors

adamjgrant avatar dinubs avatar gautamkrishnar avatar mal avatar tarungarg546 avatar

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.