web或winfrom如何直接与网页交互?高分等了 简单的说就比如QQ的注册,我如何得到他网页的信息,以及post给他数据并且让他接受到.希望给个思路或者提供相应的类,或者代码.谢谢了 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 应该是用WEBREQUEST/WEBRESPONSE或WEBHTTPREQUEST/。两个类吧然后读取response的回应流,分析 使用DOM(文档对象模型) 将HTML文档解析为DOM,然后遍历每个节点,在其中搜索关键字并进行相应替换处理即可。 public partial class HilightDemo : Form { //…… private void btnHilight_Click(object sender, EventArgs e) { HTMLDocument document = (HTMLDocument)webBrowser.Document.DomDocument; IHTMLDOMNode bodyNode = (IHTMLDOMNode)webBrowser.Document.Body.DomElement; string keyword = txtKeyword.Text.Trim(); if (keyword == "") return; HilightText(document, bodyNode, keyword); } private void HilightText(HTMLDocument document, IHTMLDOMNode node, string keyword) { // nodeType = 3:text节点 if (node.nodeType == 3) { string nodeText = node.nodeValue.ToString(); // 如果找到了关键字 if (nodeText.Contains(keyword)) { IHTMLDOMNode parentNode = node.parentNode; // 将关键字作为分隔符,将文本分离,并逐个添加到原text节点的父节点 string[] result = nodeText.Split(new string[] { keyword }, StringSplitOptions.None); for (int i = 0; i < result.Length - 1; i++) { if (result[i] != "") { IHTMLDOMNode txtNode = document.createTextNode(result[i]); parentNode.insertBefore(txtNode, node); } IHTMLDOMNode orgNode = document.createTextNode(keyword); IHTMLDOMNode hilightedNode = (IHTMLDOMNode)document.createElement("SPAN"); IHTMLStyle style = ((IHTMLElement)hilightedNode).style; style.color = "black"; style.backgroundColor = "yellow"; hilightedNode.appendChild(orgNode); parentNode.insertBefore(hilightedNode, node); } if (result[result.Length - 1] != "") { IHTMLDOMNode postNode = document.createTextNode(result[result.Length - 1]); parentNode.insertBefore(postNode, node); } parentNode.removeChild(node); } // End of nodeText.Contains(keyword) } else { // 如果不是text节点,则递归搜索其子节点 IHTMLDOMChildrenCollection childNodes = node.childNodes as IHTMLDOMChildrenCollection; foreach (IHTMLDOMNode n in childNodes) { HilightText(document, n, keyword); } } } } http://www.cnblogs.com/topboy/archive/2007/02/01/636510.html 谢谢了 我先LOOK下 看看思路 有些验证就是摆设比如CSDN丢人啊~~~~~ try{ string sPostDate="username=u&Password=p"; string sReturnString=""; UTF8Encoding encoding=new UTF8Encoding(); byte[] byte1=encoding.GetBytes(sPostDate); HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://www.exsoon.com"); request.CookieContainer=new CookieContainer(); request.Method="POST"; request.Accept="*.*"; request.ContentLength=sPostDate.Length; request.ContentType="application/x-www-form-urlencoded"; request.ServicePoint.Expect100Continue = false; Stream newStream=request.GetRequestStream(); newStream.Write(byte1,0,byte1.Length); //request.get request.Timeout=3000; HttpWebResponse response = (HttpWebResponse) request.GetResponse(); byte[] buf = new byte[46000]; string xx=response.StatusCode + "//" + response.StatusDescription; Stream resStream = response.GetResponseStream(); //resStream.Write(byte1,0,byte1.Length); int count = resStream.Read(buf, 0, buf.Length); sReturnString=sReturnString+Encoding.Default.GetString(buf,0,count); resStream.Close(); newStream.Close();}catch(Exception ex){ sReturnString=ex.Message;} 首先用工具或者直接看它的HTML源代码,找到它原来表单发送的内容,然后在C#中用HttpWebRequest去发送,HttpWebResponse来接受返回的页面。 关于视觉样式 谁帮我看看这种错是为什么啊 listview能做出这个效果么? c#本身有“连接池”功能,还需设计单例的连接对象吗? WinForm程序上传文件,求助。 关于webservice的一个问题, 请问C#如何获取USB移动硬盘的盘符?DriveType返回的是与固定硬盘FIXED一样的类型 HttpWebRequest和HttpWebResponse下载地址不正确的问题 HttpRequest跨域访问数据的问题。 DataSet更新出现问题~请高手帮忙看看那里有问题!! 難者不會,會者不難,請教各位高手一個簡單的從文件中取字串的問題。 一个面试题目
或WEBHTTPREQUEST/。两个类吧然后读取response的回应流,分析
将HTML文档解析为DOM,然后遍历每个节点,在其中搜索关键字并进行相应替换处理即可。 public partial class HilightDemo : Form
{
//…… private void btnHilight_Click(object sender, EventArgs e)
{
HTMLDocument document = (HTMLDocument)webBrowser.Document.DomDocument;
IHTMLDOMNode bodyNode = (IHTMLDOMNode)webBrowser.Document.Body.DomElement;
string keyword = txtKeyword.Text.Trim();
if (keyword == "")
return; HilightText(document, bodyNode, keyword);
} private void HilightText(HTMLDocument document, IHTMLDOMNode node, string keyword)
{
// nodeType = 3:text节点
if (node.nodeType == 3)
{
string nodeText = node.nodeValue.ToString();
// 如果找到了关键字
if (nodeText.Contains(keyword))
{
IHTMLDOMNode parentNode = node.parentNode;
// 将关键字作为分隔符,将文本分离,并逐个添加到原text节点的父节点
string[] result = nodeText.Split(new string[] { keyword }, StringSplitOptions.None);
for (int i = 0; i < result.Length - 1; i++)
{
if (result[i] != "")
{
IHTMLDOMNode txtNode = document.createTextNode(result[i]);
parentNode.insertBefore(txtNode, node);
}
IHTMLDOMNode orgNode = document.createTextNode(keyword);
IHTMLDOMNode hilightedNode = (IHTMLDOMNode)document.createElement("SPAN");
IHTMLStyle style = ((IHTMLElement)hilightedNode).style;
style.color = "black";
style.backgroundColor = "yellow";
hilightedNode.appendChild(orgNode); parentNode.insertBefore(hilightedNode, node);
}
if (result[result.Length - 1] != "")
{
IHTMLDOMNode postNode = document.createTextNode(result[result.Length - 1]);
parentNode.insertBefore(postNode, node);
}
parentNode.removeChild(node);
} // End of nodeText.Contains(keyword)
}
else
{
// 如果不是text节点,则递归搜索其子节点
IHTMLDOMChildrenCollection childNodes = node.childNodes as IHTMLDOMChildrenCollection;
foreach (IHTMLDOMNode n in childNodes)
{
HilightText(document, n, keyword);
}
}
}
}
比如CSDN
丢人啊~~~~~
{
string sPostDate="username=u&Password=p";
string sReturnString="";
UTF8Encoding encoding=new UTF8Encoding();
byte[] byte1=encoding.GetBytes(sPostDate);
HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://www.exsoon.com");
request.CookieContainer=new CookieContainer();
request.Method="POST";
request.Accept="*.*";
request.ContentLength=sPostDate.Length;
request.ContentType="application/x-www-form-urlencoded";
request.ServicePoint.Expect100Continue = false;
Stream newStream=request.GetRequestStream();
newStream.Write(byte1,0,byte1.Length);
//request.get
request.Timeout=3000;
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
byte[] buf = new byte[46000];
string xx=response.StatusCode + "//" + response.StatusDescription;
Stream resStream = response.GetResponseStream();
//resStream.Write(byte1,0,byte1.Length);
int count = resStream.Read(buf, 0, buf.Length);
sReturnString=sReturnString+Encoding.Default.GetString(buf,0,count);
resStream.Close();
newStream.Close();
}
catch(Exception ex)
{
sReturnString=ex.Message;
}