pointsight/proto/scrapeDemo.js

58 lines
2.1 KiB
JavaScript
Raw Normal View History

2022-03-06 18:36:36 +01:00
// Trying to scrape https://www.opentopia.com/hiddencam.php?p=n for data
// THIS IS A PROTOTYPE - DO NOT USE
// [Project-Name-Here] 2021
// Current state: Able to get cams from page, get location, unable to get live feed
process.exit(1)
const fs = require("fs");
const request = require("request");
function requestCamList(n){
request("http://www.opentopia.com/hiddencam.php?showmode=standard&country=%2A&seewhat=highlyrated&p="+n, { json: false }, (err, res2, body) => {
if (err) {
throw err;
}
let part = body.split("<body>")[1]
// part = part.split('<div style="clear:both">')[0]
//part = part.split('<ul class="camgrid camgrid3">')[1]
part = part.split("/webcam/")
part.shift()
for(h in part){
part[h] = part[h].replace("\t", "")
part[h] = part[h].split('target="_self">')[0].replace('"', "").split(">")[0]
console.log(part[h])
}
return(part)
});
}
function getMoreInfo(id){
const baseurl = "http://www.opentopia.com/webcam/"
const url = baseurl + id + "?viewmode=livevideo"
request(url, { json: false }, (err, res2, body) => {
if (err) {
throw err;
}
let result = {name: "", url:"", location:{lat:0,lng:0}}
let part = body.split("<body>")[1]
camPart = part.split("<div class=\"big\">")[1]
camPart = camPart.split('<img src="')[1]
camPart = camPart.split('"')[0]
result.url = camPart
part = part.split("Facility")[1]
part = part.split("Rating")[0]
part = part.split('<label class="right">')[1]
result.name = part.split("</label></div>")[0]
result.name = result.name.replaceAll("\t", "").replaceAll(" ", "")
part = part.split("<label class=\"right geo\">")[1]
part = part.split('<span class="latitude">')[1]
result.location.lat = parseFloat(part.split("</span>")[0])
part = part.split("<span class=\"longitude\">")[1]
result.location.lng = parseFloat(part.split("</span>")[0])
console.log(result)
});
}
console.log(getMoreInfo(6576))