百分相赠,求能编译通过的代码.操作网页方面的.我努力了几月,还是没成功.
这个程序实现两个功能,
第一,从http://group.hexun.com/ZHH1997/member.html中读取 "用户名 "写到一文本文件中,如 "ZHH边缘 "等,
第二,将文本文件中的诸个用户名,填到http://group.hexun.com/qiniuzhe/invite.aspx(代码附后:)
的输入框内,再点击, "发送邀请 "
第二步的网页代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<HTML>
<HEAD>
<title> 邀请首页 </title>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<link href= "/inc/h_css_manage.css " rel= "stylesheet " type= "text/css ">
<link href= "/template/h_css_manage.css " rel= "stylesheet " type= "text/css ">
<script language= "javascript ">
function cancelinvite()
{
window.reload();
return false;
}
function submitinvite(e,e1,e2)
{
re = /[a-zA-Z][_a-zA-Z0-9]{2,100}/;
if(e.value == " " || e1.value == " ")
{
alert( "请填入用户名和邀请说明! ");
return false;
}
if(e2.value==2)
{
if(!re.test(e.value))
{
alert( "输入正确的博客名! ");
return false;
}
}
return true;
}
</script>
</HEAD>
<body class= "aud " topmargin= "0 " leftmargin= "0 ">
<div align= "center ">
<div style= "WIDTH:956px; BACKGROUND-COLOR:#f6f6f6 " align= "left ">
<!-- top_1:on -->
<table width= "100% " border= "0 " cellpadding= "0 " cellspacing= "0 " class= "li_aud_02 " style= "BACKGROUND-IMAGE: url(../images/li_aud_01.gif) ">
<tr>
<td width= "60% ">
<div class= "li_aud_02 ">
<ul class= "li_aud_04 ">
<li class= "li_aud_05 ">
<a href= "/qiniuzhe/default.html " target= "_blank " class= "liadd_04 "> 骑牛者 </a> </li>
<li class= "li_aud_05_2 "> </li>
</ul>
</div>
</td>
<td width= "40% ">
<div class= "li_aud_02 ">
<ul class= "li_aud_04 ">
<li class= 'li_aud_05 '> <a href= 'http://hexun.com/metababy/default.html ' target= '_blank ' class= 'li_2 '> [metababy] </a> <a href= 'http://wayup.hexun.com/quit.aspx?gourl=http://group.hexun.com/qiniuzhe/default.html ' class= 'li_2 '> 登 出 </a> </li>
<li class= "li_aud_05 ">
<a href= "http://group.hexun.com " target= "_blank " class= "li_2 "> 朋友圈 </a>
<li class= "li_aud_05 ">
<a href= "http://tribe.hexun.com " target= "_blank " class= "li_2 "> 和讯部落 </a>
<li class= "li_aud_05_2 ">
<a href= "http://www.hexun.com " target= "_blank " class= "li_2 "> 和讯首页 </a> </li>
</ul>
</div>
</td>
</tr>
</table>
[解决办法]
大哥,可能通过C#的WebBerower控件实现,我就用这个控件来写个灌水机的
先打开第一个网页,然后截取内容,然后打开第二个网页,填内容过去,然后点发送。
[解决办法]
用ajax技术
[解决办法]
帮顶……
[解决办法]
建议楼主,在哪出问题就问那里,分开来问
在线等你的问题
[解决办法]
其实就是蜘蛛程序,说这么多内容。你在google上搜 ”用C#语言构造蜘蛛程序“里面有代码例子
可以用主要是对网页中特定关键字的分析。
[解决办法]
抓取Web网页数据分析
Posted on 2006-05-24 14:04 无悔 阅读(3767) 评论(28) 编辑 收藏 引用 网摘 所属分类: C#编程
通过程序自动的读取其它网站网页显示的信息,类似于爬虫程序。比方说我们有一个系统,要提取BaiDu网站上歌曲搜索排名。分析系统在根据得到的数据进行数据分析。为业务提供参考数据。
为了完成以上的需求,我们就需要模拟浏览器浏览网页,得到页面的数据在进行分析,最后把分析的结构,即整理好的数据写入数据库。那么我们的思路就是:
1、发送HttpRequest请求。
2、接收HttpResponse返回的结果。得到特定页面的html源文件。
3、取出包含数据的那一部分源码。
4、根据html源码生成HtmlDocument,循环取出数据。
5、写入数据库。
程序如下:
//根据Url地址得到网页的html源码
private string GetWebContent(string Url)
{
string strResult= " ";
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
//声明一个HttpWebRequest请求
request.Timeout = 30000;
//设置连接超时时间
request.Headers.Set( "Pragma ", "no-cache ");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream streamReceive = response.GetResponseStream();
Encoding encoding = Encoding.GetEncoding( "GB2312 ");
StreamReader streamReader = new StreamReader(streamReceive, encoding);
strResult = streamReader.ReadToEnd();
}
catch
{
MessageBox.Show( "出错 ");
}
return strResult;
}
为了使用HttpWebRequest和HttpWebResponse,需填名字空间引用
using System.Net;
以下是程序具体实现过程:
private void button1_Click(object sender, EventArgs e)
{
//要抓取的URL地址
string Url = "http://list.mp3.baidu.com/topso/mp3topsong.html?id=1#top2 ";
//得到指定Url的源码
string strWebContent = GetWebContent(Url);
richTextBox1.Text = strWebContent;
//取出和数据有关的那段源码
int iBodyStart = strWebContent.IndexOf( " <body ", 0);
int iStart = strWebContent.IndexOf( "歌曲TOP500 ", iBodyStart);
int iTableStart = strWebContent.IndexOf( " <table ", iStart);
int iTableEnd = strWebContent.IndexOf( " </table> ", iTableStart);
string strWeb = strWebContent.Substring(iTableStart, iTableEnd - iTableStart + 8);
//生成HtmlDocument
WebBrowser webb = new WebBrowser();
webb.Navigate( "about:blank ");
HtmlDocument htmldoc = webb.Document.OpenNew(true);
htmldoc.Write(strWeb);
HtmlElementCollection htmlTR = htmldoc.GetElementsByTagName( "TR ");
foreach (HtmlElement tr in htmlTR)
{
string strID = tr.GetElementsByTagName( "TD ")[0].InnerText;
string strName = SplitName(tr.GetElementsByTagName( "TD ")[1].InnerText, "MusicName ");
string strSinger = SplitName(tr.GetElementsByTagName( "TD ")[1].InnerText, "Singer ");
strID = strID.Replace( ". ", " ");
//插入DataTable
AddLine(strID, strName, strSinger, "0 ");
string strID1 = tr.GetElementsByTagName( "TD ")[2].InnerText;
string strName1 = SplitName(tr.GetElementsByTagName( "TD ")[3].InnerText, "MusicName ");
string strSinger1 = SplitName(tr.GetElementsByTagName( "TD ")[3].InnerText, "Singer ");
//插入DataTable
strID1 = strID1.Replace( ". ", " ");
AddLine(strID1, strName1, strSinger1, "0 ");
string strID2 = tr.GetElementsByTagName( "TD ")[4].InnerText;
string strName2 = SplitName(tr.GetElementsByTagName( "TD ")[5].InnerText, "MusicName ");
string strSinger2 = SplitName(tr.GetElementsByTagName( "TD ")[5].InnerText, "Singer ");
//插入DataTable
strID2 = strID2.Replace( ". ", " ");
AddLine(strID2, strName2, strSinger2, "0 ");
}
//插入数据库
InsertData(dt);
dataGridView1.DataSource = dt.DefaultView;
}
程序运行结果界面图:
以上程序在VS.Net2005(C#),Windows 2003(sp1)平台上测试通过。