python调用站长之家多地ping
没找到API接口, 翻了翻请求记录. 随便写写
站长的调用大概是先请求https://ping.chinaz.com/目标网站, 获取到服务器列表, token和id, 然后在通过token和id在去请求节点服务器


爬虫的知识确实没学过, 看了一下返回结果, 长度都是相同的, 独有的字符是token, 于是就按行取出带有token的行, 然后在字符串切片. 以后搞了爬虫在取的好看点
import requests
import os
site = input("请输入要查询的网站: ")
info = requests.get("https://ping.chinaz.com/{}".format(site))
token_list = []
if os.path.isfile("xx.html"):
os.remove("xx.html")
with open("xx.html", "a+", encoding="utf8") as f:
f.write(info.text)
with open("xx.html", "r", encoding="utf8") as f:
for strvar in f:
if "token" in strvar:
id_val = strvar.strip()[39:75]
token_val = strvar.strip()[120:152]
token_list.append((id_val, token_val))
del token_list[len(token_list) - 1]
for strvar in token_list:
url = "https://ping.chinaz.com/pingcheck?host=%s&guid=%s&token=%s" % (site, strvar[0], strvar[1])
print(requests.get(url).text)
浙公网安备 33010602011771号