Trích:
Nguyên văn bởi hoc_picpicpic
chào bạn mình cũng đang tìm hiểu về cái này. mình có thể viết đc giao diện kết nối máy tính với PIC = c# nhưng lài ko biết cách lấy dữ liệu từ web và bóc tách thế nào, bạn có thể nói giúp mình cách làm như thế nào ko?
|
Bạn có thể dùng streamreader
vd:
Code:
public string Get()
{
try
{
String _string = "";
WebRequest request = WebRequest.Create("http://abcd.xx/");
using (WebResponse response = request.GetResponse())
{
using (StreamReader stream = new StreamReader(response.GetResponseStream()))
{
_string = stream.ReadToEnd();
}
}
int first = _string.IndexOf("Address: ") + 9;
int last = _string.LastIndexOf("</body>");
_string = _string.Substring(first, last - first);
return _string;
}
catch (Exception ex)
{
MessageBox.Show(ex.toString());
return "Loi";
}
}
Namespace :using System.Data;