Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2f4bce4

Browse files
final commit
1 parent bc3219c commit 2f4bce4

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
const Nightmare = require('nightmare')
2+
const cheerio = require('cheerio');
3+
const nightmare = Nightmare({ show: true });
4+
const url = 'https://www.flipkart.com/';
5+
6+
nightmare
7+
.goto(url)
8+
.wait('body')
9+
.click('button._2AkmmA._29YdH8')
10+
.type('input.LM6RPg', 'laptop')
11+
.click('button.vh79eN')
12+
.wait('div.bhgxx2')
13+
.evaluate(() => document.querySelector('body').innerHTML)
14+
.end()
15+
.then(response => {
16+
console.log(getData(response));
17+
}).catch(err => {
18+
console.log(err);
19+
});
20+
21+
let getData = html => {
22+
data = [];
23+
const $ = cheerio.load(html);
24+
$('div._1HmYoV._35HD7C:nth-child(2) div.bhgxx2.col-12-12').each((row, raw_element) => {
25+
$(raw_element).find('div div div').each((i, elem) => {
26+
let title = $(elem).find('div div a:nth-child(2)').text();
27+
let link = $(elem).find('div div a:nth-child(2)').attr('href');
28+
if (title) {
29+
data.push({
30+
title : title,
31+
link : link
32+
});
33+
}
34+
});
35+
});
36+
return data;
37+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /