访问太频繁拒绝访问怎么办?

artwl_cn artwl_cn 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
小弟写了一个博客备份工具,在备份的过程中要对每篇博客地址进行访问,取得网页源码进行备份。
现在遇到的问题是,当备份到150篇左右时,网站拒绝访问了,也就是说访问太频繁被拒绝了,这个备份程序放在一个单独的类库中,请问怎么控制访问的频率(能不能用线程等待实现,如果能请指点一下),有没有其他好的解决方案?
简要代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;

namespace BlogMoveLib
{
public class BlogAnalysis
{
public IList<Blog> Analysis(IList<string> BlogAllUrl)
{
string content;
Blog model=new Blog();
IList<Blog> blogList = new List<Blog>();
foreach(string url in BlogAllUrl)
{
content=GetHtml(url);
model = GetBlogInfo(content);
blogList.Add(model);
}
if (blogList.Count > 0)
return blogList;
return null;
}

/// <summary>
/// 获得网址原代码
/// </summary>
/// <param name="Url">网址</param>
/// <returns>string</returns>
private string GetHtml(string Url)
{
//过程省略
}

/// <summary>
/// 解析博客主体
/// </summary>
/// <param name="content">网页源码</param>
/// <returns>博客实体</returns>
private Blog GetBlogInfo(string content)
{
//...过程省略
}
}
}
...全文

相关推荐

评论 24
收藏 已收藏
分享
返回顶部
artwl_cn
.NET社区 62,275 成员 668,968 内容