Skip to content

Instantly share code, notes, and snippets.

@arn-ob
Created December 22, 2019 10:40
Show Gist options
  • Save arn-ob/925ced01bcf900b14518f50addec2fe2 to your computer and use it in GitHub Desktop.
Save arn-ob/925ced01bcf900b14518f50addec2fe2 to your computer and use it in GitHub Desktop.
Request Scrap problem Solved
// const axios = require('axios');
// const cheerio = require('cheerio');
// const url = 'https://khaasfood.com';
// axios(url)
// .then(response => {
// const html = response.data;
// const s = cheerio.load(html);
// console.log(html)
// // console.log(statsTable.length);
// })
// .catch(console.error);
// Worked
const request = require('request');
const cheerio = require('cheerio');
const url = 'https://khaasfood.com/';
var options = {
url: url,
headers: {
'User-Agent': 'request',
'Content-Type': 'text/html; charset=utf-8'
}
};
request(options, function (error, result, html) {
console.log({ error, sts: result.statusCode })
if (!error && result.statusCode == 200) {
var s = cheerio.load(html);
console.log(s.html())
} else {
console.log('Error')
}
})
// let a = new Promise((resolve, reject) => {
// request(options, function(error, result, html){
// console.log({error, sts: result.statusCode})
// if (!error && result.statusCode == 200) {
// var s = cheerio.load(html);
// // console.log("response", response)
// // console.log(s.html())
// resolve(s.html())
// } else {
// resolve('err')
// }
// })
// })
// a.then(res => {
// console.log(res)
// })
// var xhttp = new XMLHttpRequest();
// xhttp.onreadystatechange = function() {
// if (this.readyState == 4 && this.status == 200) {
// console.log("Hello", this.responseText)
// }
// };
// xhttp.open("GET", "https://khaasfood.com/", true);
// xhttp.send();
// var rp = require('request-promise');
// const cheerio = require('cheerio');
// const url = 'https://mobipath.online';
// var options = {
// uri: url,
// transform: function (body) {
// return cheerio.load(body);
// }
// };
// rp(options)
// .then(function (htmlString) {
// const s = cheerio.load(htmlString);
// console.log(s.html())
// })
// .catch(function (err) {
// console.log(err)
// });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment