Created
September 1, 2021 23:35
-
-
Save AskAlice/c6d0f82eae6feed75c0a1e1c7f31fb6e to your computer and use it in GitHub Desktop.
USPS informed delivery scraping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const packages = []; | |
document.querySelectorAll("div.pack_row").forEach(package => { | |
let pack = {} | |
const details = package.querySelector(".pack_details #coltextR2"); | |
const greenText = details.querySelector("span:nth-child(5)")?.innerText; | |
pack.provider = greenText?.startsWith("Delivered at") ? undefined : greenText; | |
pack.trackingNumber = details.querySelector(".pack_h4").innerText.replace("/\s/g", ""); | |
const statusArray = package.querySelector(".pack_coltext").innerText.trim().replace(/[\s\t]{2,}/g,"~~").split("~~"); | |
const statusKeys = ["status","longStatus","date"]; | |
pack = {...pack, ...Object.fromEntries(statusKeys.map((_, i) => [statusKeys[i], statusArray[i]]))} | |
packages.push(pack); | |
}); | |
console.log(packages); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment