This python script will scrape cpl website to get the checked out items and due dates for the books you've borrowed. This script returns a json array of your books:
[
{
"book_title": "Cracking the Coding Interview",
"days_remaining": "17 days remaining",
"due_date": "Sep 10, 2019"
},
{
"book_title": "Vicious",
"days_remaining": "19 days remaining",
"due_date": "Sep 12, 2019"
}
]
- The script gets the login page first and extracts the csrf-token.
- Then this crsf-token along with user credentials is POSTed
- The session is now created. Another request is made to get the checked out items
- Using BeautifulSoup the page is scraped to get the div items holding all the information required for each book
Enter your cpl user name and password in config.json file.
{
"username" : "<<user_name>>",
"password" : "<<password>>"
}
This is a python3 script and the scraping is done using BeautifulSoup package.
Install the requirements:
pip3 install requests, beautifulsoup4
python3 scarpe.py
You can also make this as an api call using Flask. You can look at my other project where I'm using this script as an api call using flask (link to be up soon)
Add hold item status to the json
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.