The Python language has been gaining prominence and popularity. Its simple, clear and concise syntax has endeared Python to many developers, especially first-time programmers. Moreover, Python’s repertoire of readily available libraries (on Data Frames, Matrices, Graphical Plots, Machine Learning) could significantly shorten development cycle time.
In this example, we’ll demo the simplicity and versatility of Python by just writing 9 lines of code (excluding comments) to do the following 3 tasks:
- Scrape the real-time prices of Straits Times Index (STI) at 5-min intervals from a typical financial website (e.g. Bloomberg, Yahoo Finance, …).
- Parse the scraped data returned to extract the timestamps and the corresponding closing STI prices.
- Display the timestamps (in Weekday-Month-Day-Year-Hr-Min format) and corresponding closing prices beginning from 0900 hr (commencement of trading).
The Python code is shown below: