starthq / search

Search provider API docs & integration implementations.
https://starthq.com
32 stars 26 forks source link

Diigo #45

Closed olegp closed 10 years ago

ilbambino commented 10 years ago

Here it is my fast approach for Diigo:

{
  search: [
    {
      type:'link',
      query:'https://www.diigo.com/search?adSScope=my&what={{term}}&snapshot=no',
      translate:'parseHTML(response)',
      name:{
        selector:'Titleinner',
        expression:'element.getElementsBySelector('a')[0].textContent'
      },
      link:{
        selector:'Titleinner',
        expression:'element.getElementsBySelector('a')[0].getAttribute("href")'
      },
      description:{
        selector:'.description',
        expression:'element.getElementsBySelector('a')[0].textContent'
      }
    }
  ]
}

But so far it doesn't work. When I try to search using it I get the following error: screen shot 2014-07-15 at 20 55 56

As it is expected the request is not even sent to the diigo servers. (Doesn't show in the Dev console as a request done).

So it is not fully tested, as I cannot really test it. But the selectors work, and the expression also. And the documentation doesn't explicitly say it, but I guess that when the expression is run, the element matched by the selector is named 'element'.

Diigo has a complex DOM, lots of nested divs, and what makes it even more 'complex' is that the classes of the links are like 'title_#' being the # the number of the link returned in the page. (Not only with title but more classes like that are used). And that's the reason to use that kind of expression to navigate through the items. Not very robust but should work once the other issue is solved.

One last thing, the descritption is the same as name. I don't know if the description is optional (nothing in the docs about it) and I have never use the extension before, so I cannot really say if in other apps there is a difference.

olegp commented 10 years ago

You can ignore the error, it's not caused by the code running your provider.

There are some issues with your selectors, it should be '.Titleinner' instead of 'Titleinner'.

More importantly, you're mixing single and double quotes in your expressions which is what's breaking things and preventing the request from being made.

For example, replace the following line:

    expression:'element.getElementsBySelector('a')[0].textContent'

with:

    expression:'element.getElementsBySelector("a")[0].textContent'
ilbambino commented 10 years ago

True, the doc says that if there are errors it probably is a problem with the definition, but as I saw that one I skipped that part. Anyway, with this one works now:

{
  search: [
    {
      type:'link',
      query:'https://www.diigo.com/search?adSScope=my&what={{term}}&snapshot=no',
      translate:'parseHTML(response)',
      name:{
        selector:'.Titleinner',
        expression:'element.textContent.trim()'
      },
      link:{
        selector:'.Titleinner',
        expression:'element.firstElementChild.href'
      },
      description:{
        selector:'.Titleinner',
        expression:'element.textContent.trim()'
      }
    }
  ]
}
olegp commented 10 years ago

Works great, thanks! Can you please create a pull request or commit directly to master?