-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
82 lines (70 loc) · 1.81 KB
/
App.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
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
const cheerio = require('react-native-cheerio');
const instructions = Platform.select({
ios: 'Check debugger/console for output',
android: 'Check debugger/console for output',
});
export default class App extends Component {
componentDidMount(){
this.scrapeHTMLContent("https://www.amazon.in/?ref=gw_intl_in&pf_rd_p=4c740c5e-7140-40f3-8386-f749c0cf29ca&pf_rd_r=2HTAXTAEYHKAA1QJRFEV")
.then((response) => {
console.log('REsponse is '+response)
this.readData(response);
})
.catch(err => console.log(`Error is ${JSON.stringify(err)}`));
}
scrapeHTMLContent = (url) => {
const axios = require('axios');
return new Promise((resolve, reject) => {
axios.get(url).then((response) => {
if (response.status === 200) resolve(response.data);
else reject(response.data);
});
});
}
readData = (data) => {
const $ = cheerio.load(data);
const mainContent = $('title', '');
//To find plain string/text from html
// const mainContent = $('title', '').text();
console.log('Main content is ',mainContent);
const footer = $('div', 'footer');
console.log('Fotter content is ',footer);
}
render() {
return (
<View style={styles.container}>
<Text>{instructions}</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});