Undefined property: HTML5DOMElement::$1 when using querySelector on DOMElement
godbout opened this issue · comments
Is there anything I'm missing?
The HTML5DOMDocument is loaded correctly. I'm getting a DOMNodeList that I'm going through. For each element I want to do a querySelector but I get thrown an exception and can't figure out why... Any idea? Thanks!
Code 255: Fatal error: Uncaught exception 'Exception' with message 'Undefined property: HTML5DOMElement::$1'
I've done some tests and cannot reproduce the problem. Can you show us the code you've written?
Hi, thanks for checking!
I think it might be because the HTML I receive from my curl call doesn't seem to be valid?
Anyway, here's the code (arranged and tested to give you an example of when I do have the issue):
$dom = new IvoPetkov\HTML5DOMDocument();
$dom->loadHTML(
'
<table cellpadding="0" cellspacing="0" class="data" style="width: 100%">
<tr class="firstr">
<th class="width100perc nopad">torrent name</th>
<th class="center"><a href="https://kickass.cd/usearch/dexter/?field=size&sorder=desc" rel="nofollow">size</a></th>
<th class="center"><span><a href="https://kickass.cd/usearch/dexter/?field=time_add&sorder=desc" rel="nofollow">age</a></span></th>
<th class="center"><span class="seed"><a href="https://kickass.cd/usearch/dexter/?field=seeders&sorder=desc" rel="nofollow">seed</a></span></th>
<th class="lasttd nobr center"><a href="https://kickass.cd/usearch/dexter/?field=leechers&sorder=desc" rel="nofollow">leech</a></th>
</tr>
<tr class="odd" id="torrent_latest_torrents12975568">
<td>
<div class="iaconbox center floatright">
<a class="icommentjs kaButton smallButton rightButton"> 6 <i class="ka ka-comment"></i></a>
<a class="icon16" href="/dexter-s01-season-1-1080p-5-1ch-bluray-reenc-deejayahmed-tt10011005" title="Verified Torrent"><i class="ka ka16 ka-verify ka-green"></i></a>
<a data-nop title="Torrent magnet link" href="magnet:?xt=urn:btih:38aa0fa30b084183d329e8aef6643cab2779e39a&dn=Dexter+S01+Season+1+1080p+5.1Ch+BluRay+ReEnc-DeeJayAhmed&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fpublic.popcorn-tracker.org%3A6969" class="icon16"><i class="ka ka16 ka-magnet"></i></a>
<a data-download title="Download torrent file" href="magnet:?xt=urn:btih:38aa0fa30b084183d329e8aef6643cab2779e39a&dn=Dexter+S01+Season+1+1080p+5.1Ch+BluRay+ReEnc-DeeJayAhmed&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fpublic.popcorn-tracker.org%3A6969" class="icon16"><i class="ka ka16 ka-arrow-down"></i></a>
</div>
<div class="torrentname">
<a href="/dexter-s01-season-1-1080p-5-1ch-bluray-reenc-deejayahmed-tt10011005" class="torType Video"></a>
<a href="/dexter-s01-season-1-1080p-5-1ch-bluray-reenc-deejayahmed-tt10011005" class="normalgrey font12px plain bold"></a>
<div class="markeredBlock torType VideoType">
<a href="/dexter-s01-season-1-1080p-5-1ch-bluray-reenc-deejayahmed-tt10011005.html" class="cellMainLink">Dexter S01 Season 1 1080p 5.1Ch BluRay ReEnc-DeeJayAhmed</a>
<span class="font11px lightgrey block">
Posted by <i title="Verified Uploader" class="ka ka-verify" style="font-size: 16px;color:orange;"></i> DeeJayPirate in <span id="cat_12975568"><strong><a href="/Video/">Video</a></strong></span> </span>
</div>
</td>
<td class="nobr center"> 8.22 GiB </span>
</td>
<td class="center" title=" 04-21 2014"> 04-21 2014</td>
<td class="green center">128</td>
<td class="red lasttd center">65</td>
</tr>
<tr class="odd" id="torrent_latest_torrents12975568">
<td>
<div class="iaconbox center floatright">
<a class="icommentjs kaButton smallButton rightButton"> 2 <i class="ka ka-comment"></i></a>
<a class="icon16" href="/dexter-s04-season-4-1080p-5-1ch-bluray-reenc-deejayahmed-tt10458722" title="Verified Torrent"><i class="ka ka16 ka-verify ka-green"></i></a>
<a data-nop title="Torrent magnet link" href="magnet:?xt=urn:btih:aea022ca415d47cf28b5a43e26a7ed16b91651d3&dn=Dexter+S04+Season+4+1080p+5.1Ch+BluRay+ReEnc-DeeJayAhmed&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fpublic.popcorn-tracker.org%3A6969" class="icon16"><i class="ka ka16 ka-magnet"></i></a>
<a data-download title="Download torrent file" href="magnet:?xt=urn:btih:aea022ca415d47cf28b5a43e26a7ed16b91651d3&dn=Dexter+S04+Season+4+1080p+5.1Ch+BluRay+ReEnc-DeeJayAhmed&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fpublic.popcorn-tracker.org%3A6969" class="icon16"><i class="ka ka16 ka-arrow-down"></i></a>
</div>
<div class="torrentname">
<a href="/dexter-s04-season-4-1080p-5-1ch-bluray-reenc-deejayahmed-tt10458722" class="torType Video"></a>
<a href="/dexter-s04-season-4-1080p-5-1ch-bluray-reenc-deejayahmed-tt10458722" class="normalgrey font12px plain bold"></a>
<div class="markeredBlock torType VideoType">
<a href="/dexter-s04-season-4-1080p-5-1ch-bluray-reenc-deejayahmed-tt10458722.html" class="cellMainLink">Dexter S04 Season 4 1080p 5.1Ch BluRay ReEnc-DeeJayAhmed</a>
<span class="font11px lightgrey block">
Posted by <i title="Verified Uploader" class="ka ka-verify" style="font-size: 16px;color:orange;"></i> DeeJayPirate in <span id="cat_12975568"><strong><a href="/Video/">Video</a></strong></span> </span>
</div>
</td>
<td class="nobr center"> 7.94 GiB </span>
</td>
<td class="center" title=" 06-30 2014"> 06-30 2014</td>
<td class="green center">76</td>
<td class="red lasttd center">50</td>
</tr>
<tr class="odd" id="torrent_latest_torrents12975568">
<td>
<div class="iaconbox center floatright">
<a class="icommentjs kaButton smallButton rightButton"> 7 <i class="ka ka-comment"></i></a>
<a class="icon16" href="/dexter-s03-season-3-1080p-5-1ch-bluray-reenc-deejayahmed-tt10110116" title="Verified Torrent"><i class="ka ka16 ka-verify ka-green"></i></a>
<a data-nop title="Torrent magnet link" href="magnet:?xt=urn:btih:48c21344c44507076fa67f3a5caf8c9d46f5c5e7&dn=Dexter+S03+Season+3+1080p+5.1Ch+BluRay+ReEnc-DeeJayAhmed&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fpublic.popcorn-tracker.org%3A6969" class="icon16"><i class="ka ka16 ka-magnet"></i></a>
<a data-download title="Download torrent file" href="magnet:?xt=urn:btih:48c21344c44507076fa67f3a5caf8c9d46f5c5e7&dn=Dexter+S03+Season+3+1080p+5.1Ch+BluRay+ReEnc-DeeJayAhmed&tr=udp%3A%2F%2Ftracker.leechers-paradise.org%3A6969&tr=udp%3A%2F%2Fzer0day.ch%3A1337&tr=udp%3A%2F%2Ftracker.coppersurfer.tk%3A6969&tr=udp%3A%2F%2Fpublic.popcorn-tracker.org%3A6969" class="icon16"><i class="ka ka16 ka-arrow-down"></i></a>
</div>
<div class="torrentname">
<a href="/dexter-s03-season-3-1080p-5-1ch-bluray-reenc-deejayahmed-tt10110116" class="torType Video"></a>
<a href="/dexter-s03-season-3-1080p-5-1ch-bluray-reenc-deejayahmed-tt10110116" class="normalgrey font12px plain bold"></a>
<div class="markeredBlock torType VideoType">
<a href="/dexter-s03-season-3-1080p-5-1ch-bluray-reenc-deejayahmed-tt10110116.html" class="cellMainLink">Dexter S03 Season 3 1080p 5.1Ch BluRay ReEnc-DeeJayAhmed</a>
<span class="font11px lightgrey block">
Posted by <i title="Verified Uploader" class="ka ka-verify" style="font-size: 16px;color:orange;"></i> DeeJayPirate in <span id="cat_12975568"><strong><a href="/Video/">Video</a></strong></span> </span>
</div>
</td>
<td class="nobr center"> 7.94 GiB </span>
</td>
<td class="center" title=" 05-07 2014"> 05-07 2014</td>
<td class="green center">74</td>
<td class="red lasttd center">33</td>
</tr>
</table>
');
$rows = $dom->querySelector('table.data')->querySelectorAll('tr.odd');
foreach ($rows as $row) {
$size = $row->querySelector('.nobr');
}
The full error message from Alfred debug:
Code 255: Fatal error: Uncaught exception 'Exception' with message 'Undefined property: HTML5DOMElement::$1' in /Users/guill/Dropbox/Development/alfred-kat/commands/vendor/ivopetkov/html5-dom-document-php/src/HTML5DOMElement.php:37
Stack trace:
#0 /Users/guill/Dropbox/Development/alfred-kat/commands/vendor/ivopetkov/html5-dom-document-php/src/HTML5DOMDocument/Internal/QuerySelectors.php(85): IvoPetkov\HTML5DOMElement->__get('1')
#1 /Users/guill/Dropbox/Development/alfred-kat/commands/vendor/ivopetkov/html5-dom-document-php/src/HTML5DOMDocument/Internal/QuerySelectors.php(16): IvoPetkov\HTML5DOMElement->internalQuerySelectorAll('.nobr', 1)
#2 /Users/guill/Dropbox/Development/alfred-kat/commands/vendor/ivopetkov/html5-dom-document-php/src/HTML5DOMElement.php(149): IvoPetkov\HTML5DOMElement->internalQuerySelector('.nobr')
#3 /Users/guill/Dropbox/Development/alfred-kat/commands/query.php(107): IvoPetkov\HTML5DOMElement->querySelector('.nobr')
#4 {main}
thrown in /Users/guill/Dropbox/Development/alfred-kat/commands/vendor/ivopetkov/html5-dom-document-php/src/HTML5DOMElement.php on line 37
I found and fixed the problem. Expect a new release in couple of minutes.
😍
I should have checked the source code more, but I was not sure I was even using the methods correctly. Excellent, thanks!