抓取 站为:https://luoyang.anjuke.com/sale/m530/=baidu-cpc-luoyang-tyong1&kwid=90923896685中的数据
前台:
后台:
public static string GetHtmlStr(string url)
{
try
{
WebRequest rGet = WebRequest.Create(url);
WebResponse rSet = rGet.GetResponse();
Stream s = rSet.GetResponseStream();
StreamReader reader = new StreamReader(s, Encoding.UTF8);
return reader.ReadToEnd();
}
catch (WebException)
{
//连接失败
return null;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
string url = “https://luoyang.anjuke.com/sale/m530/=baidu-cpc-luoyang-tyong1&kwid=90923896685”;
string htmlstr = GetHtmlStr(url);
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.LoadHtml(htmlstr);
HtmlNode rootnode = doc.DocumentNode; //XPath路径表达式,这里表示选取所有span节点中的font最后一个子节点,其中span节点的class属性值为num
//根据 页的内容设置XPath路径表达式
string xpathstringting = “//div[@class=’details-item’]/span”;
//string xpathstringping = “//div[@class=’details-item’]/em[@class=’spe-lines’]”;
HtmlNodeCollection aa = rootnode.SelectNodes(xpathstringting); //所有找到的节点都是一个集合
//HtmlNodeCollection bb = rootnode.SelectNodes(xpathstringping);
string sPath = @”C:UsersAdministratorDesktopJQuery练习4.14爬虫高德支付宝WeebPaTwo” + “\”;
Directory.CreateDirectory(sPath);
for (int i = 0; i {
string innertext = aa[i].InnerText;
Response.Write(“
“);
Response.Write(innertext);
}
}
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!