【发布时间】:2017-02-15 17:56:47
【问题描述】:
我必须得到一个网络的 HTML 代码,然后才能找到这个类:
<span class='uccResultAmount'>0,896903</span>
我已尝试使用 正则表达式。
还有Streams,我的意思是,将整个HTML 代码存储在string 中。但是,string 的代码非常大。所以这是不可能的,因为0,896903 我正在搜索的数量在string 中不存在。
有没有办法只读取 Stream 的一小部分?
部分方法:
public static string getValue()
{
string data = "not found";
string urlAddress = "http://www.xe.com/es/currencyconverter/convert/?Amount=1&From=USD&To=EUR";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream receiveStream = response.GetResponseStream();
StreamReader readStream = null;
if (response.CharacterSet == null)
{
readStream = new StreamReader(receiveStream);
}
else
{
readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
}
data = readStream.ReadToEnd(); // the string in which I should search for the amount
response.Close();
readStream.Close();
}
如果您找到更简单的方法来解决我的问题,请告诉我。
【问题讨论】:
标签: c# html string stream substring