2019-10-17 21:43:53 +02:00
|
|
|
const request = require('request')
|
2019-10-15 09:22:08 +02:00
|
|
|
|
2019-10-17 21:43:53 +02:00
|
|
|
const useMobileURL = (originalURL) => {
|
|
|
|
const url = new URL(originalURL)
|
2019-10-15 09:22:08 +02:00
|
|
|
|
2019-10-17 21:43:53 +02:00
|
|
|
return `${url.protocol}//mobile.facebook.com${url.port}${url.pathname}${url.hash}`
|
|
|
|
}
|
2019-10-15 09:22:08 +02:00
|
|
|
|
2019-10-17 21:43:53 +02:00
|
|
|
const crawl = async (originalURL) => {
|
|
|
|
const url = useMobileURL(originalURL)
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
console.info(`Started request for URL: ${url}`)
|
|
|
|
request({
|
|
|
|
url,
|
|
|
|
headers: {
|
|
|
|
'Accept-Language': 'en-US, en',
|
|
|
|
'User-Agent': 'request',
|
|
|
|
},
|
|
|
|
}, (err, res, body) => {
|
|
|
|
if (err) {
|
|
|
|
reject(err)
|
|
|
|
return
|
|
|
|
}
|
2019-10-16 08:59:47 +02:00
|
|
|
|
2019-10-17 21:43:53 +02:00
|
|
|
console.info(`Finished request for URL: ${url}`)
|
|
|
|
resolve(body)
|
|
|
|
})
|
|
|
|
})
|
2019-10-15 09:22:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = crawl
|