dharmafly / noodle

A node server and module which allows for cross-domain page scraping on web documents with JSONP or POST.
https://noodle.dharmafly.com/
745 stars 69 forks source link

Support an each command to handle iteration in one query #89

Closed AaronAcerboni closed 8 years ago

AaronAcerboni commented 11 years ago

This will make taking data from tables or lists easy.

Example:

"QUERY"

{
  "url"    : "http://example.com/people",
  "type"   : "html",
  "forEach": "tablr tr",
  "map"    : {
    "name": {
      "selector": "td.first-name"
    },
    "age" : {
      "selector": "td.age"
    }
  }
}

"RESULT"

{
  "results": [
    {
      "name": "Dorothy",
      "age": 32
    },
    {
      "name": "Martin",
      "age": 7
    },
  ],
  "created": ...
}
premasagar commented 11 years ago

Can we make it 'each' instead I 'forEach' ?

Premasagar Rose, Dharmafly http://dharmafly.com dharmafly.com / 07941 192398 premasagar.com twitter.com/premasagar L4RP.com asyncjs.com

premasagar commented 11 years ago
<div>
  <p class="bar">bar</p>
  <table>
    <tr><td class="age">1</td> <td class="name">2</td> <td class="foo">3</td> <td class="foo">4</td></tr>
  </table>
</div>

QUERY

{
  "url"    : "http://example.com/people",
  "type"   : "html",
  "map"    : {
    "bar": ".bar",
    "people": {
      "selector": "table tr",
      "map": {
        "age": {
          "selector": "td.age"
        },
        "name": {
          "selector": "td.name"
        },
        "foo": {
          "selector": "td.foo"
        }
      }
    }
  }
}

RESULT

{
  "bar": ["bar"],
  "people": [
    {
      "age": [1],
      "name": [2],
      "foo": [3, 4]
    },
    {
      "age": [1],
      "name": [2],
      "foo": [3, 4]
    }
  ]
}
codersquare-com commented 9 years ago

I've just starting working on this great library. Thanks a lot for opensourcing it What is the state of this feature ?

premasagar commented 9 years ago

I'm glad you're finding Noodle useful. This feature didn't yet make it into code. The library isn't under active development but I'm happy to review and accept pull requests, especially if they are accompanied by tests.

Premasagar Rose premasagar.com dharmafly.com twitter.com/premasagar github.com/premasagar