这是我以前写的一个方法:
public static string GetValueFromWeb(string url)
{
string html = null;
WebRequest req = WebRequest.Create(url);
WebResponse res = req.GetResponse();
Stream stream = res.GetResponseStream();
Encoding encode = Encoding.GetEncoding("UTF-8");
StreamReader sr = new StreamReader(stream, encode);
char[] readbuffer = new char[256];
int n = sr.Read(readbuffer, 0, 256);
while (n > 0)
{
string str = new string(readbuffer, 0, n);
html += str;
n = sr.Read(readbuffer, 0, 256);
}
return html;
}
string url是你想获取的页面地址,返回值是string,你可以用string类中的方法如LastIndexOf方法等查找string中的数据,而"实时价格"需要你在页面设置时间进行刷新