-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathscript.js
151 lines (113 loc) · 4.39 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const request = require('request');
const cheerio = require('cheerio');
const fs = require('fs');
const argv = require('yargs').argv;
const item = argv.c;
var A = 84;
//const URI = "http://www.jiit.ac.in";
let i = 1;
/*const URI = "https://news.ycombinator.com/news";*/
//const URI = "https://news.ycombinator.com/news?p="+i;
//console.log(URI);
//for(i=1; i<13; i++)
{
//const URL1 = "https://www.flipkart.com/search?page="+i+"&q="+item;
const URL1 = "https://docs.google.com/spreadsheets/u/2/d/e/2PACX-1vT8lxJxfrzlpr8WJvRYoFm5B7eAHryssyFLzEet3Qx5hvB12zd4febjEr0ZW2tsc9bTTrQf1zMsLhud/pubhtml?gid=1563395941&single=true";
//const URL1 = "http://www.shopclues.com/search?q="+item;
/*let complete_data = {};
let extract_data;
let URL_Item;
let final_url;
let price;
let rating;
complete_data = {
"extract_data" : extract_data,
"URL_Item" : URL_Item,
"final_url": final_url,
"price" : price,
"rating": rating
};*/
request(URL,function (error,response,body) {
/*var URI = "https://news.ycombinator.com/news?p="+i;
console.log(URI);
console.log(i);*/
if(error)
{
console.log(error);
}
//console.log('Status Code Of Request: '+ response.statusCode);
if(response.statusCode===200)
{
console.log("Everything Is Working Fine");
}
const $ = cheerio.load(body);
//console.log(body);
//const extract_data={};
/*const data = $(this).find('div._1-2Iqu');
//console.log(data);
console.log(data.text());*/
const complete_data = {};
//main code goes here
//$('div._2SxMvQ >div._3T_wwx >div._2-gKeQ').each(function (index) {
$('div#sheets-viewport >div#1563395941 >div.ritz > .waffle').each(function (index) {
//complete_data.extract_data = $(this).find('div._1-2Iqu> div.col-7-12>div._3wU53n').text();
let extract_data = $(this).find('tr:nth-child(0)').text();
console.log(extract_data+'\n');
console.log("Ashishkr");
//console.log(complete_data.extract_data.text);
// complete_data.URL_Item = "https://www.flipkart.com"+$(this).find('a._1UoZlX').attr('href');
//complete_data.final_url = "https://www.flipkart.com"+complete_data.URL_Item.text();
//complete_data.price = $(this).find('div._1-2Iqu>div._2o7WAb > div._6BWGkk >div._1uv9Cb> div._2rQ-NK').text();
//complete_data.rating = $(this).find('div._1-2Iqu> div.col-7-12>div.niH0FQ>span._2_KrJI>div.hGSR34').text();
// console.log(data);
// console.log(rating.text());
//console.log(URL_Item);
//console.log(data.text());
A = A+1;
//fs.appendFileSync('output/flipkart_iphone.json',data.text()+', '+' '+price.text()+', '+rating.text()+'\n'+final_url+'\n\n');
fs.appendFileSync('output/cs_viv.json',"\"Item"+A+"\""+":"+JSON.stringify(complete_data)+','+'\n\n');
//console.log(index)
})
}
)}
/* const extract_ = {
"data" = extr*/
//console.log($);
//console.log($);
/*var title;
var link;*/
//$('tr.athing').each(function (index) {
//var extract_data = {};
//extract_data.title = $(this).find('td.title > a').text();
//extract_data.link = $(this).find('td.title > a').attr('href');
/*console.log(title);
console.log(link);
console.log(' ');*/
/*fs.appendFileSync('output/hackernews_new2_obj.txt',extract_data.title+'\n'+extract_data.link+'\n\n');*/
//console.log(extract_data);
//fs.appendFileSync('output/hackernews_obj_extract.JSON', JSON.stringify(extract_data)+','+'\n\n');
//})
//});
/*request(URI,function (error,response,body) {
if(error)
{
console.log(error);
}
//console.log('Status Code Of Request: '+ response.statusCode);
if(response.statusCode===200)
{
console.log("Everything Is Working Fine");
}
const $ = cheerio.load(body);
//console.log($);
var title;
var link;
$('tr.athing').each(function (index) {
title = $(this).find('td.title > a').text();
link = $(this).find('td.title > a').attr('href');
/!*console.log(title);
console.log(link);
console.log(' ');*!/
fs.appendFileSync('hackernews_new1.txt',title+'\n'+link+'\n\n');
})
});*/