Code Monkey home page Code Monkey logo

wcl.js's Introduction

wcl.js

This is my wonky attempt at providing the Wellington City Libraries user info as JSON!

Why? It's a fun challenge! I don't reaaaally need it but it's particularly annoying to scrape as is.

What's the trouble?

Well, firstly they don't use https which speaks for itself. The site uses JSP which isn't an issue itself. It also uses iFrames which also isn't much trouble.

What is, is that account data isn't rendered to HTML but rather, you get HTML with your account data as an inline Javascript array.

For starters, this is a pain because you can't scrape using something like cURL since it's only applied to the DOM when open in your browser window.

Well, that's fine, we can just build the DOM using JSDOM except oh wait, it references a file which it can't build which ruins that.

This is what I've build so far to get around it all. I basically regex the inline script out of the fetched page and apply it to an empty DOM. JSDOM can then execute the script and I can regex some more until we've got a nice clean object.

It worksβ„’ but it's not perfect. I had a quick look at reverse engineering whatever they use to serve up data to their android app and I know roughly where it comes from but the URLs are obscured as hell plus it's mostly processed internally meaning you can't just spin up Wireshark and snag URLs.

Similarly, I decompiled the WCL Android app and the URLs are comprised of about 20 or 30 different segments which are all fairly obscured so yeah, one day I'll make something out of this if I can figure out a nice solution.

Also, fetching charges (checked out books) sometimes errors out with a status 500 for no great reason so that's a thing too.

What's the next step?

You could probably cleanup some bits and add cookiejar support. Axios has an unofficial helper library here.

This project has been pretty tiring and I'm ready to just put it on hold indefinitely. I learnt a bunch about JSDOM and cookies so that's cool but I'm probably way out of my depth to be honest. You're welcome to pair on it or submit PRs though. Let me know and I'll write up everything I know so far.

wcl.js's People

Watchers

James Cloos avatar  avatar

wcl.js's Issues

Incorrect cookies

At times, it seems to fetch an invalid cookie. I need to do some more testing to find out what causes it. There's also times that the server returns a 500 error which I can't do much about.

It's one of those bugs where it feels like anytime I try look at what might be causing it, it suddenly fixes itself

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.