choru-k/react-native-html-parser

What is "findSelector"?

Closed this issue · 10 comments

The readme shows:

console.log(findSelector('div.aa#in[ii="a"]'))

but I cannot find findSelector anywhere. I was unable to get querySelect to find based on any attribute, I resorted to getElementsByAttribute, but I would really prefer to use a css selector.

sorry. README is wrong. findSelector is not there. You can use querySelect or getElementsBySelector. I think findSelector is same as getElementsBySelector

Okay, querySelect wouldn't work though. When I did querySelect('input[name="authenticity-token"]'), it returned an array of all 6 inputs of any type on the page.

ok.

var DOMParser = require('../dom-parser').DOMParser;
var doc = new DOMParser().parseFromString(
    '<html><body>'+
    '<div id="a" class="a">'+
        '<a class="b">abcd</a>'+
    '</div>'+
    '<div class="b">'+
        '<a href="aa" id="b">'+
    '</div>'+
    '<input name="abc" />' +
    '<input name="bbb" />' +
    '</body></html>'
    ,'text/html');

console.log(doc.querySelect('input[name="bbb"]').map((elem) => elem.attributes))
console.log('end')

When I tested this code, I got only <input name="bbb" /> element. Could you test this code?

Yours works for me. I don't know what the difference is. I am parsing the text returned from a fetch, and this is what I get:

image

As you can see, I only have one in the document, but I get six matches. take a closer look:

image

The first one is named "utf8", not "authenticity_token". The next one is named "email", and it goes on.

Sorry. I don't know why yours cannot work. If you send your HTML and your code, I debug it and fix library.

Oh, I also spent some time to figure it out.

@ohtangza Could you give me your html code? If you send it, I will debug it and fix library.

@g6ling Oh, your parser basically worked. I just could not find findSelector() in the library. Just a matter of documentation as you mentioned.

Btw, 한국인이시네요? :)

@ohtangza thanks. I fixed it. f8a61b1

네 반갑습니다 :)

@g6ling Thanks for your effort. Cheers!