Created
January 14, 2017 07:23
-
-
Save anonymous/c460d15187a61a25e8bf83c69fd6a1ee to your computer and use it in GitHub Desktop.
Sample python3 script to scrape real-time data from an APS Systems ECU
This file contains 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
# | |
# Sample python3 script to scrape real-time data from an APS Systems ECU, software version 3.10.10 | |
# The '###' comments are instructions for setting this up to work on your system | |
# | |
### needs the bs4 libary, so "$ pip install bs4" | |
from bs4 import BeautifulSoup | |
import urllib.request | |
### Change this IP to match your ECU IP address | |
ecuIP = "192.168.1.67" | |
url = "http://" + ecuIP + "/cgi-bin/parameters?target=main" | |
# scrape the table from the real time data page of the ECU | |
table = BeautifulSoup(urllib.request.urlopen(url),"html.parser").find("table") | |
# grab the data from table rows, noting that the "[1:]" means skip the header row | |
for row in table.find_all("tr")[1:]: | |
# for each of the columns, strip out any data after the   (i.e. the units) so we can store as numbers | |
# for now I'm just printing the data, but it would be easy to push it into a database | |
print("ID: " + row.contents[0].get_text().split("\xa0")[0]) | |
print("Power: " + row.contents[1].get_text().split("\xa0")[0]) | |
print("Freq: " + row.contents[2].get_text().split("\xa0")[0]) | |
print("Volts: " + row.contents[3].get_text().split("\xa0")[0]) | |
print("Temp: " + row.contents[4].get_text().split("\xa0")[0]) | |
# Need to update this code to parse the date so we could store it as a datetime field in a database | |
print("Date: " + row.contents[5].get_text().split("\xa0")[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment