Get basic navigation in
This commit is contained in:
parent
964ed37d56
commit
51802893b1
54
index.js
54
index.js
@ -4,11 +4,21 @@ function sleep(ms) {
|
|||||||
return new Promise((resolve) => setTimeout(resolve, ms))
|
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const settlePromises = async (promiseArray) => {
|
||||||
|
const settledArray = await Promise.allSettled(promiseArray)
|
||||||
|
let errors = settledArray.filter((resolved) => resolved.reason)
|
||||||
|
if (errors.length) {
|
||||||
|
throw errors
|
||||||
|
}
|
||||||
|
return settledArray.map((resolved) => resolved.value)
|
||||||
|
}
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
const browser = await puppeteer.launch({
|
const browser = await puppeteer.launch({
|
||||||
headless: false,
|
headless: false,
|
||||||
ignoreHTTPSErrors: true,
|
ignoreHTTPSErrors: true,
|
||||||
|
executablePath: "/usr/bin/chromium",
|
||||||
})
|
})
|
||||||
console.log("Opened Browser")
|
console.log("Opened Browser")
|
||||||
const page = await browser.newPage()
|
const page = await browser.newPage()
|
||||||
@ -19,48 +29,44 @@ async function main() {
|
|||||||
page.on("request", (request) => {
|
page.on("request", (request) => {
|
||||||
let url = request.url()
|
let url = request.url()
|
||||||
console.log("request url", url)
|
console.log("request url", url)
|
||||||
if (url == "usefulrequest") {
|
if (url.includes("getWebActivityFeed")) {
|
||||||
usefulRequestHeaders = { ...request.headers() }
|
usefulRequestHeaders = { ...request.headers() }
|
||||||
console.log("hello!")
|
console.log("hello!", usefulRequestHeaders)
|
||||||
}
|
}
|
||||||
request.continue()
|
request.continue()
|
||||||
})
|
})
|
||||||
|
|
||||||
await page.goto("https://www.google.com")
|
await page.goto("https://drivers.uber.com/earnings/activities")
|
||||||
console.log("Went to Page")
|
console.log("Went to Page")
|
||||||
|
|
||||||
await page.waitForSelector('button[type="submit"]')
|
await page.waitForSelector('input[aria-label="Select a date range."]')
|
||||||
await page.type('input[name="userId"]', "username")
|
console.log("We're in.", usefulRequestHeaders)
|
||||||
await page.type('input[name="password"]', "password")
|
|
||||||
console.log("Typed Credentials")
|
|
||||||
await page.click('button[type="submit"]')
|
|
||||||
|
|
||||||
for (let i = 0; i < 10; i++) {
|
for (let i = 0; i < 10; i++) {
|
||||||
if (usefulRequestHeaders.headerName) {
|
await sleep(500)
|
||||||
await browser.close()
|
if (usefulRequestHeaders["content-type"]) {
|
||||||
return console.log("success")
|
console.log("success")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if (i == 9) {
|
||||||
|
throw "fail"
|
||||||
}
|
}
|
||||||
await sleep(300)
|
|
||||||
}
|
}
|
||||||
console.log("after sleep loop")
|
console.log("after sleep loop")
|
||||||
|
|
||||||
// const response = await fetch(
|
const response = await fetch("https://www.google.com", {
|
||||||
// "https://www.google.com",
|
method: "POST",
|
||||||
// {
|
headers: usefulRequestHeaders,
|
||||||
// method: "POST",
|
body: JSON.stringify({ Request }),
|
||||||
// headers: usefulRequestHeaders,
|
})
|
||||||
// body: JSON.stringify({Request
|
|
||||||
// }),
|
|
||||||
// }
|
|
||||||
// );
|
|
||||||
|
|
||||||
// if (response.ok) {
|
// if (response.ok) {
|
||||||
// console.log(await response.json());
|
// console.log(await response.json());
|
||||||
// }
|
// }
|
||||||
|
|
||||||
await browser.close()
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return console.error("Critical failure", err)
|
console.error("Critical failure", err)
|
||||||
|
} finally {
|
||||||
|
await browser.close()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
{
|
{
|
||||||
|
"type": "module",
|
||||||
"name": "ubercrawler",
|
"name": "ubercrawler",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Puppeteer application for crawling uber and lyft for tax information",
|
"description": "Puppeteer application for crawling uber and lyft for tax information",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"test": "echo \"Error: no test specified\" && exit 1",
|
||||||
|
"start": "node index.js"
|
||||||
},
|
},
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
Loading…
Reference in New Issue
Block a user