GetHttpWebRequest抓取不到这个站的内容,大神们帮看看

qq_254097620 2016-01-08 08:43:58
抓取百度的正常 抓取http://3g.16cp.com/gamedraw/more.aspx?name=lucky 就不行了代码如下

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


namespace LotteryNumsCollect
{
class collect
{
private string phasenc;
private string dataArrStrnc;

private static string GetHttpWebRequest(string url)
{
Uri requestUri = new Uri(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(requestUri);
request.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:2.0.1) Gecko/20100101 Firefox/4.0.1";
request.Accept = "*/*";
request.KeepAlive = true;
request.Headers.Add("Accept-Language", "zh-cn,en-us;q=0.5");
HttpWebResponse response = null;
try
{
response = (HttpWebResponse)request.GetResponse();
}
catch (WebException exception)
{
if (exception.Status == WebExceptionStatus.ProtocolError)
{
return string.Empty;
}
}
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream, Encoding.GetEncoding("utf-8"));
string str = reader.ReadToEnd();
reader.Close();
responseStream.Close();
response.Close();
return str;
}










public void getFilenc()
{
try
{
string url = "http://3g.16cp.com/gamedraw/more.aspx?name=lucky";
string str2 = GetHttpWebRequest(url);

Console.WriteLine(str2);
Console.ReadKey();
}
catch (Exception)
{
}
}






static void Main(string[] args)
{
collect p = new collect();
p.getFilenc();

}



}
}

...全文
118 3 打赏 收藏 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
save4me 2016-01-12
  • 打赏
  • 举报
回复
使用你的代码,测试第一次能够正常抓取。之后好像一直是服务器超时。不知道是服务器不稳定还是对爬虫做了判断处理。 另外页面上的下一页按钮使用的POST方法
lthaoyue 2016-01-11
  • 打赏
  • 举报
回复
加上下面语句试试 request.ContentType = "application/json"; request.Method = "GET";
Justin-Liu 2016-01-09
  • 打赏
  • 举报
回复
用fiddler分析一下看看

62,270

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧