Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] "OR" query #188

Open
KaKi87 opened this issue Jun 4, 2023 · 0 comments
Open

[Feature request] "OR" query #188

KaKi87 opened this issue Jun 4, 2023 · 0 comments

Comments

@KaKi87
Copy link

KaKi87 commented Jun 4, 2023

Hello,

Let's consider the following HTML :

<a class="itemA" href="https://example.com"><span>example.com</span></a>
<a class="itemA" href="https://example.net"><span>example.net</span></a>
<div class="itemB"><a href="https://example.org"><span>example.org</span></a></div>
<div class="itemB"><a href="https://example.edu"><span>example.edu</span></a></div>

Out of which I would like to get the following :

{
  "items": [
    {
      "title": "example.com",
      "url": "https://example.com"
    },
    {
      "title": "example.net",
      "url": "https://example.net"
    },
    {
      "title": "example.org",
      "url": "https://example.org"
    },
    {
      "title": "example.edu",
      "url": "https://example.edu"
    }
  ]
}

But since .itemA & .itemB elements have a different structure despite containing the same data, the only way to currently parse those is the following :

{
  'itemsA': {
    listItem: '.itemA',
    data: {
      'title': {
        selector: 'span'
      },
      'url': {
        attr: 'href'
      }
    }
  },
  'itemsB': {
  	listItem: '.itemB',
    data: {
    	'title': {
      	selector: 'span'
      },
      'url': {
      	selector: 'a',
        attr: 'href'
      }
    }
  }
}

(JSFiddle demo)

And then use [...itemsA, ...itemsB].

Therefore, I would like to suggest adding an OR query, e.g. :

{
  'items': {
    listItem: '.itemA, .itemB',
    data: {
      'title': {
        selector: 'span'
      },
      'url': {
        or: [
          {
            attr: 'href'
          },
          {
            selector: 'a',
            attr: 'href'
          }
        ]
      }
    }
  }
}

Which would directly return the desired output.

Additionally, I have the following question : how could I get the title property if there was no span element ?

Thanks


PS : thank you for this library, I dreamt several times for years of finding or creating something like this until I stumbled on it yesterday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant