标签:ext request ring validate 软件 取数 lin 循环 back
相关软件点击下载
登录的处理。因为有些网页数据需要登陆后才能提取。这里要使用ieHTTPHeaders来提取登录时的提交信息。
抓取网页
如果出现乱码,调整编码集为gb2312或者是utf-8
-------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.VisualStudio.TestTools.WebTesting;
using HtmlAgilityPack;
publicclassWebTest1Coded : WebTest
{
publicoverrideIEnumerator<WebTestRequest> GetRequestEnumerator()
{
WebTestRequest request1 = newWebTestRequest("http://www.microsoft.com/");
request1.ValidateResponse += newEventHandler<ValidationEventArgs>(request1_ValidateResponse);
yieldreturn request1;
}
void request1_ValidateResponse(object sender, ValidationEventArgs e)
{
//load the response body string as an HtmlAgilityPack.HtmlDocument
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(e.Response.BodyString);
//locate the "Nav" element
HtmlNode navNode = doc.GetElementbyId("Nav");
//pick the first <li> element
HtmlNode firstNavItemNode = navNode.SelectSingleNode(".//li");
//validate the first list item in the Nav element says "Windows"
e.IsValid = firstNavItemNode.InnerText == "Windows";
}
}
标签:ext request ring validate 软件 取数 lin 循环 back
原文地址:http://www.cnblogs.com/coky/p/6702734.html