private int CatchContent(string strUrl)
{
int count = 0;
int scount = 0;
int fcount = 0;
try
{
datas d = new datas();
WebClient wc = new WebClient();
string group = GroupList.SelectedValue.ToString();
string type = LinkList.SelectedValue.ToString();
Regex r = new Regex("<ol>[\\s\\S]*?</ol>", RegexOptions.IgnoreCase);
Regex r0 = new Regex("<h3 class=\"r\">[\\s\\S]*?</h3>", RegexOptions.IgnoreCase);
Regex r1 = new Regex("http[\\s\\S]*?target", RegexOptions.IgnoreCase);
string html = Encoding.UTF8.GetString(wc.DownloadData(strUrl));
html = r.Match(html).Value;
for (Match m = r0.Match(html); m.Success; m = m.NextMatch())
{
string url = r1.Match(m.Value).Value;
url = url.Replace("target", "").Replace("\"", "");
//写数据库
int i = d.LinkIn(url, url, "0", this.UserId, group, type);
if (i == 1)
scount++;
else
fcount++;
count++;
}
wc.Dispose();
}
catch { }
return count;
}这是源代码
string html = Encoding.UTF8.GetString(wc.DownloadData(strUrl));在这里报 503 服务器不可用错误
在网上看了很多资料 最终大致确定Googel可能是有防抓取设置
求高手解决
不想用WebRequest 因为需改动的代码较多
{
int count = 0;
int scount = 0;
int fcount = 0;
try
{
datas d = new datas();
WebClient wc = new WebClient();
string group = GroupList.SelectedValue.ToString();
string type = LinkList.SelectedValue.ToString();
Regex r = new Regex("<ol>[\\s\\S]*?</ol>", RegexOptions.IgnoreCase);
Regex r0 = new Regex("<h3 class=\"r\">[\\s\\S]*?</h3>", RegexOptions.IgnoreCase);
Regex r1 = new Regex("http[\\s\\S]*?target", RegexOptions.IgnoreCase);
string html = Encoding.UTF8.GetString(wc.DownloadData(strUrl));
html = r.Match(html).Value;
for (Match m = r0.Match(html); m.Success; m = m.NextMatch())
{
string url = r1.Match(m.Value).Value;
url = url.Replace("target", "").Replace("\"", "");
//写数据库
int i = d.LinkIn(url, url, "0", this.UserId, group, type);
if (i == 1)
scount++;
else
fcount++;
count++;
}
wc.Dispose();
}
catch { }
return count;
}这是源代码
string html = Encoding.UTF8.GetString(wc.DownloadData(strUrl));在这里报 503 服务器不可用错误
在网上看了很多资料 最终大致确定Googel可能是有防抓取设置
求高手解决
不想用WebRequest 因为需改动的代码较多
解决方案 »
- 请教c#中如何在加载鼠标.cur文件时使用相对路径?
- 怎么用xsd?
- 一个简单的字符串对比问题
- 如何拆分word的表格。很急啊!!!!!!!
- 请问,如何将网页文件放到资源文件的包里,然后用webbrowser加载资源文件包里的网页?
- 讨论一下,.net程序的效率。
- 在 RichTextBox 中如何“最快”得到光标所在的行数!!!( 已有2种常用方法 ) 100 送给最快的兄弟。。
- 各位大虾 请问这两本 C#入门经典 哪一本更好些?
- 关于操作excel的问题:----com没有注册。。。
- C#操作数据库,一次如何更新多条记录且保证了事务
- 送分贴..一个简单问题
- 只给了个webservice的地址,还有用户名和密码,我该怎么用?
当判断是程序访问时 会返回如上错误
以前我的做法是 当出这问题了 换代理 然后用代理去 就行 但是代理也用不太久 次数一多 google又给断了 再换另一个代理 清cookie
看了一篇文章介绍说有个API专门给程序员研究访问的 后来封了
很是麻烦啊
求高手高见 在线等
同时HTTP头部信息Header不要使用默认的,要使用多个不同的头信息来采集,否则很容易是机器抓取的.