实现访问先安装requests
pip install requests
本人使用的是python3实现
直接上代码
# -*- coding: utf-8 -*-
import requests
import time
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.84 Safari/537.36',
'Referer': 'https://blog.csdn.net/',
'Host': 'blog.csdn.net'
}
# 获取页面源码
def GetHtml(url):
try:
res = requests.get(url=url, headers=headers)
except:
return None
return res.text
# url_pre地址为自己的博客地址即可
url_pre = "https://blog.csdn.net/........"
# list列表放入自己博客的文章后缀
list = [84850042,85246109,84872441,84849342,88654891,84849342]
j=0
# 使用无限循环访问,间歇60秒
while True:
for index,i in enumerate(list):
url = url_pre+str(i)
#print(url)
GetHtml(url)
time.sleep(1)
j += 1
#print(" ", j ,"次循环访问已完成")
print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime()))
time.sleep(60)
其中运行这个文件时候可能会出现404页面,打开自己要刷新的博客网站,按F12键,找到network获取User-Agent替换文件中header头信息
谢谢,all