您可以使用Python的requests库来访问网站并获取源代码,然后使用字符串的查找和切片操作来提取所需的值。下面是一个示例代码:

import requests

# 发送GET请求获取网页源代码
response = requests.get("http://sy.cjh.com.cn/index.html")
source_code = response.text

# 查找时间
start_index = source_code.find('"stnm":"朱沱","tm":') + len('"stnm":"朱沱","tm":')
end_index = source_code.find('"wptn":', start_index)
time = source_code[start_index:end_index]

# 查找涨落
start_index = source_code.find('"stnm":"朱沱","tm":', end_index) + len('"stnm":"朱沱","tm":')
end_index = source_code.find('","z":', start_index)
wptn = source_code[start_index:end_index]

# 查找水位
start_index = source_code.find('","z":', end_index) + len('","z":')
end_index = source_code.find('"}', start_index)
water_level = source_code[start_index:end_index]

# 判断涨落值并生成输出字符串
if wptn == '5':
    movement = "正在涨水"
elif wptn == '4':
    movement = "正在落水"
else:
    movement = ""

# 打印输出
print("朱沱水文站:更新时间:{},实时水位:{}m,{}".format(time, water_level, movement))

请注意,这只是一个示例代码,具体的查找位置和切片操作可能需要根据网页源代码的实际情况进行调整


原文地址: http://www.cveoy.top/t/topic/h8as 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录