first commit
This commit is contained in:
44
smart.py
Normal file
44
smart.py
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import requests, base64
|
||||
from requests.auth import HTTPDigestAuth
|
||||
from bs4 import BeautifulSoup
|
||||
import urllib3
|
||||
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
||||
|
||||
user= '1707910897002706169923_ECPR0002108185'
|
||||
password = 'V!lhanhan03'
|
||||
url = 'https://192.168.1.200/cgi-bin/hanservice.cgi'
|
||||
s = requests.Session()
|
||||
res=s.get(url,auth=HTTPDigestAuth(user, password),verify=False)
|
||||
cookies = { 'Cookie' : res.cookies.get('session')}
|
||||
|
||||
soup = BeautifulSoup(res.content, 'html.parser')
|
||||
tags = soup.find_all('input')
|
||||
token = tags[0].get('value')
|
||||
action = 'meterform'
|
||||
post_data = "tkn=" + token + "&action=" + action
|
||||
|
||||
res = s.post(url, data=post_data,cookies=cookies,verify=False)
|
||||
|
||||
soup = BeautifulSoup(res.content, 'html.parser')
|
||||
sel = soup.find(id='meterform_select_meter')
|
||||
meter_val = sel.findChild()
|
||||
meter_id = meter_val.attrs.get('value')
|
||||
post_data = "tkn=" + token + "&action=showMeterProfile&mid=" + meter_id
|
||||
|
||||
res= s.post(url, data=post_data,cookies=cookies,verify=False)
|
||||
|
||||
soup = BeautifulSoup(res.content, 'html.parser')
|
||||
table_data = soup.find('table', id="metervalue")
|
||||
result_data = {
|
||||
'value': table_data.find(id="table_metervalues_col_wert").string,
|
||||
'unit': table_data.find(id="table_metervalues_col_einheit").string,
|
||||
'timestamp': table_data.find(id="table_metervalues_col_timestamp").string,
|
||||
'isvalid': table_data.find(id="table_metervalues_col_istvalide").string,
|
||||
'name': table_data.find(id="table_metervalues_col_name").string,
|
||||
'obis': table_data.find(id="table_metervalues_col_obis").string
|
||||
}
|
||||
print(result_data['timestamp']+ " " + result_data['value']+ " " + result_data['unit'])
|
||||
s.close()
|
||||
|
||||
Reference in New Issue
Block a user