-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from baconcheese113/master
Less strict matching for getElementsByClass
- Loading branch information
Showing
5 changed files
with
50 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,48 @@ | ||
var DOMParser = require('react-native-html-parser').DOMParser; | ||
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>'+ | ||
'</body></html>' | ||
,'text/html'); | ||
`<html><body> | ||
<div id="a" class="a"> | ||
<a class="b">abcd</a> | ||
</div> | ||
<div id="a" class="a"> | ||
<a class="b">efgh</a> | ||
</div> | ||
<div class="b a andEvenMore" name="my-element"> | ||
<a href="aa" id="b" /> | ||
</div> | ||
<div class="a b c d"> | ||
<div class="video video_link" href="www.myvideos.com/video1.mp4"> | ||
<p class="tiny text duration">3:40</p> | ||
<img data-src="www.myvideos.com\/video1.png" alt="video1 image" /> | ||
</div> | ||
</div> | ||
<div class="a b c d"> | ||
<div class="video video_link" href="www.myvideos.com/video2.mp4"> | ||
<p class="tiny text duration">9:33</p> | ||
<img data-src="www.myvideos.com\/video2.png" alt="video2 image" /> | ||
</div> | ||
</div> | ||
<div class="a b c d"> | ||
<div class="video video_link" href="www.myvideos.com/video3.mp4"> | ||
<p class="tiny text duration">4:21</p> | ||
<img data-src="www.myvideos.com\/video3.png" alt="video3 image" /> | ||
</div> | ||
</div> | ||
</body></html>` | ||
,'text/html'); | ||
|
||
// console.log(doc.getElementsByAttribute('class', 'b')); | ||
var ulResults = Array.from(doc.getElementsByClassName('video_link', false)) | ||
ulResults.forEach(el => console.log(el.getAttribute("href").replace(/\\/g, ''))) | ||
ulResults.forEach(el => console.log(el.querySelect('img')[0].getAttribute("alt"))) | ||
ulResults.forEach(el => console.log(el.getElementsByClassName('duration', false)[0].textContent)) | ||
// console.log(ulResults[0].querySelect('img')[0].getAttribute("alt")) | ||
|
||
//console.log(doc.getElementsByAttribute('class', 'b')); | ||
//console.log(doc.querySelect('.div.aa class#a a')) | ||
// console.log(doc.querySelect('.div.aa class#a a')) | ||
//console.log(doc.findSelector('div.aa#in[ii="a"]')) | ||
//console.log(doc.getElementsBySelector('a[href="aa"]#b')) | ||
//console.log(doc.getElementsBySelector('div.b')) | ||
console.log(doc.querySelect('div.a a.b')) | ||
console.log('end') |