File tree 2 files changed +29
-2
lines changed
2 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -59,4 +59,11 @@ export const WwwRedditComExtractor = {
59
59
'div a[data-test-id="comments-page-link-num-comments"]' ,
60
60
] ,
61
61
} ,
62
+
63
+ extend : {
64
+ comments : {
65
+ selectors : [ 'div[data-testid="comment"]' ] ,
66
+ allowMultiple : true ,
67
+ } ,
68
+ } ,
62
69
} ;
Original file line number Diff line number Diff line change 1
1
import assert from 'assert' ;
2
- import URL from 'url' ;
3
2
import cheerio from 'cheerio' ;
4
3
import moment from 'moment-timezone' ;
4
+ import URL from 'url' ;
5
5
6
- import Mercury from 'mercury' ;
7
6
import getExtractor from 'extractors/get-extractor' ;
7
+ import Mercury from 'mercury' ;
8
8
import { excerptContent } from 'utils/text' ;
9
9
10
10
const fs = require ( 'fs' ) ;
@@ -224,5 +224,25 @@ describe('WwwRedditComExtractor', () => {
224
224
225
225
assert . equal ( embed . length , 1 ) ;
226
226
} ) ;
227
+
228
+ it ( 'returns the comments' , async ( ) => {
229
+ const html = fs . readFileSync (
230
+ './fixtures/www.reddit.com--title-only.html'
231
+ ) ;
232
+ const uri =
233
+ 'https://www.reddit.com/r/AskReddit/comments/axtih6/what_is_the_most_worth_it_item_you_have_ever/' ;
234
+
235
+ const { comments } = await Mercury . parse ( uri , { html } ) ;
236
+
237
+ const expectedCommentsLength = 12 ;
238
+ assert . equal ( comments . length , expectedCommentsLength ) ;
239
+
240
+ const first13 = excerptContent ( comments [ 0 ] || '' , 13 ) ;
241
+
242
+ assert . equal (
243
+ first13 ,
244
+ 'A Miele canister vacuum. I had read the 4 AMAs from the vacuum'
245
+ ) ;
246
+ } ) ;
227
247
} ) ;
228
248
} ) ;
You can’t perform that action at this time.
0 commit comments