python网站主动推送

import requests
import random


def tuisong():
# urls用来存放需要推送的网站url,根据自己的实际网站数量添加
urls = {
'vc': '/urls?site=www.victorytestseo.com&token=k6V0Pq2c7BSmMgIb',
'fs': '/urls?site=www.firsttestseo.com&token=k6V0Pq2c7BSmMgIb',
'qc': '/urls?site=www.threetestseo.com&token=k6V0Pq2c7BSmMgIb',
'ws': '/urls?site=www.fourtestseo.com&token=k6V0Pq2c7BSmMgIb',
'jf': '/urls?site=www.jianfeiketang.com&token=k6V0Pq2c7BSmMgIb',
'yf': '/urls?site=www.maiclothes.com&token=k6V0Pq2c7BSmMgIb',
'ys': '/urls?site=www.maiclothes.com&token=k6V0Pq2c7BSmMgIb'
}
url = random.choice(list(urls.keys()))
input_choice = input('请输入要推送的网站:')
if input_choice == 'vc':
url = urls['vc']
filecontents = {'file': open('./vc.txt', 'rb')}
r = requests.post('http://data.zz.baidu.com' + url, files=filecontents)
baiduresult = "推送成功,结果为{}".format(r.text)
return baiduresult
elif input_choice == 'fs':
url = urls['fs']
filecontents = {'file': open('./fs.txt', 'rb')}
r = requests.post('http://data.zz.baidu.com' + url, files=filecontents)
baiduresult = "推送成功,结果为{}".format(r.text)
return baiduresult
elif input_choice == 'qc':
url = urls['qc']
filecontents = {'file': open('./qc.txt', 'rb')}
r = requests.post('http://data.zz.baidu.com' + url, files=filecontents)
baiduresult = "推送成功,结果为{}".format(r.text)
return baiduresult
elif input_choice == 'ws':
url = urls['ws']
filecontents = {'file': open('./ws.txt', 'rb')}
r = requests.post('http://data.zz.baidu.com' + url, files=filecontents)
baiduresult = "推送成功,结果为{}".format(r.text)
return baiduresult
elif input_choice == 'jf':
url = urls['jf']
filecontents = {'file': open('./jf.txt', 'rb')}
r = requests.post('http://data.zz.baidu.com' + url, files=filecontents)
baiduresult = "推送成功,结果为{}".format(r.text)
return baiduresult
elif input_choice == 'yf':
url = urls['yf']
filecontents = {'file': open('./yf.txt', 'rb')}
r = requests.post('http://data.zz.baidu.com' + url, files=filecontents)
baiduresult = "推送成功,结果为{}".format(r.text)
return baiduresult
elif input_choice == 'ys':
url = urls['ys']
filecontents = {'file': open('./ys.txt', 'rb')}
r = requests.post('http://data.zz.baidu.com' + url, files=filecontents)
baiduresult = "推送成功,结果为{}".format(r.text)
return baiduresult
elif input_choice == 'q':
exit()
else:
print('网址输入有误,请检查要推送的网站')


if __name__ == "__main__":
i = 0
while i < 5:
baidu = tuisong()
print(baidu)
i += 1
点赞