import requests
import random
import ddddocr
from fake_useragent import UserAgent
ua = UserAgent()
user_Agent = ua.random
headers = {
"User-Agent": user_Agent,
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Accept-Language": "zh-CN,zh;q=0.9",
"Accept-Encoding": "gzip, deflate, br",
"DNT": "1",
"Connection": "cloes"
}
ocr = ddddocr.DdddOcr()
if __name__ == '__main__':
num = random.uniform(0, 1)
# Verification code
img_src = 'https://www.jlwater.com/captcha?' + str(num)
print("Verification code url: " + img_src)
r = requests.get(img_src, headers=headers)
# save cookie
cookies = r.cookies.items()
cookie = ''
for name, value in cookies:
cookie += '{0}={1};'.format(name, value)
# save Verification code img
# with open("yzm.jpeg", "wb") as f:
# f.write(r.content)
res = ocr.classification(r.content)
print("The code is:", res)
# login
url = "https://www.jlwater.com/user/ajaxLogin"
payload = {
"mobile": "填写你的手机号",
"password": "抓包查看下加密后的",
"code": res,
"url": ""
}
headers = {
"User-Agent": user_Agent,
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
"Accept-Language": "zh-CN,zh;q=0.9",
"Accept-Encoding": "gzip, deflate, br",
"cookie": cookie
}
res = requests.post(url, data=payload, headers=headers)
cookies = r.cookies.items()
for name, value in cookies:
cookie += '{0}={1};'.format(name, value)
# water fee
url = "https://www.jlwater.com/waterFee/getConsWaterFeeSummary"
payload = {'consNo': '你的户号'}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
可以使用Node-Red直接调用