web或winfrom如何直接与网页交互?高分等了
简单的说就比如QQ的注册,我如何得到他网页的信息,以及post给他数据并且让他接受到.
希望给个思路或者提供相应的类,或者代码.谢谢了
[解决办法]
应该是用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
[解决办法]
自动注册是不可能,现在基本都用图像验证功能了,不知道有没有人可以破。
------解决方案--------------------
用HttpWebRequest
[解决办法]
有些验证就是摆设
比如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来接受返回的页面。