从Htt的presponse读取特定的div [英] Read specific div from HttpResponse
本文介绍了从Htt的presponse读取特定的div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我送1 HttpWebRequest和读取响应。
我快满页面的响应。
我想获得1格是从响应名称的广告费率。
所以,我怎么能这种模式匹配?
I am sending 1 httpWebRequest and reading the response. I am getting full page in the response. I want to get 1 div which is names ad Rate from the response. So how can I match that pattern?
我的code是这样的:
My code is like:
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("http://www.domain.com/");
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
Stream response = WebResp.GetResponseStream();
StreamReader data = new StreamReader(response);
string result = data.ReadToEnd();
像
我得到的回应:
I am getting response like:
<HTML><BODY><div id="rate">Todays rate 55 Rs.</div></BODY></HTML>
我想读的div率的数据。即我应该得到的内容今天率55卢比。
I want to read data of div rate. i.e. I should get Content "Todays rate 55 Rs."
所以,我怎样才能使正则表达式这个???
So how can I make regex for this???
推荐答案
敏捷性包可以加载和解析该文件对你来说,没有必要乱流和响应:
The HTML Agility Pack can load and parse the file for you, no need for messy streams and responses:
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load("http://jsbin.com/owobe3");
HtmlNode rateNode = doc.DocumentNode.SelectSingleNode("//div[@id='rate']");
string rate = rateNode.InnerText;
这篇关于从Htt的presponse读取特定的div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文