本人想用C#做一个信息抓取系统,想在新浪网上抓取新闻。前提是我已经在新浪网上已登陆的。请问应该怎么实现?

summba 2010-01-05 05:21:58
请教各位帅哥们:


本人想用C#做一个信息抓取系统,想在新浪网上抓取新闻。前提是我已经在新浪网上已登陆的。请问应该怎么实现?
...全文
156 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
hua_88617 2010-01-05
  • 打赏
  • 举报
回复
public static byte[] GetHtmlByBytes(string server, string URL, byte[] byteRequest, string cookie, out string header)
{
long contentLength;
HttpWebRequest httpWebRequest;
HttpWebResponse webResponse;


httpWebRequest = (HttpWebRequest)HttpWebRequest.Create(URL);
CookieContainer co = new CookieContainer();
co.SetCookies(new Uri(server), cookie);


httpWebRequest.CookieContainer = co;

httpWebRequest.ContentType = "application/x-www-form-urlencoded";
httpWebRequest.Accept = "application/x-shockwave-flash, image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";



httpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
httpWebRequest.Headers.Add("Accept-Language", "zh-cn");



//是否支持重新定向
//httpWebRequest.AllowAutoRedirect = false;

httpWebRequest.Method = "GET";
httpWebRequest.Timeout = 15000;
httpWebRequest.ContentLength = byteRequest.Length;

webResponse = (HttpWebResponse)httpWebRequest.GetResponse();
//header = webResponse.Headers.ToString();
header = webResponse.Headers.Get("Set-Cookie");
if (string.IsNullOrEmpty(header))
{
header = cookie;
}
else
{
header = cookie + "," + header;
}
//getStream = webResponse.GetResponseStream();


Stream gzips = webResponse.GetResponseStream();

contentLength = webResponse.ContentLength;
byte[] outBytes = new byte[0];
outBytes = ReadFully(gzips);
gzips.Close();


return outBytes;
}
public static byte[] ReadFully(Stream stream)
{
byte[] buffer = new byte[128];
using (MemoryStream ms = new MemoryStream())
{
while (true)
{
int read = stream.Read(buffer, 0, buffer.Length);
if (read <= 0)
return ms.ToArray();
ms.Write(buffer, 0, read);
}
}
}
guyehanxinlei 2010-01-05
  • 打赏
  • 举报
回复
将需要请求的页面内容获取到,找匹配的信息
cuike519 2010-01-05
  • 打赏
  • 举报
回复
自己模拟请求吧,大概也就是个Cookie不好处理,搞定就ok了。
wzp144650 2010-01-05
  • 打赏
  • 举报
回复
httpwebrequest
httpwebresponse
马老虎 2010-01-05
  • 打赏
  • 举报
回复
本来想回答的看见0.00%就算了!!bangding
dyufei 2010-01-05
  • 打赏
  • 举报
回复
待解
Return门徒 2010-01-05
  • 打赏
  • 举报
回复
??不了,帮顶接分

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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