PDA

View Full Version : Lỗi bóc tách dữ liệu xin mọi người chỉ giúp



srylove
26-04-2011, 14:44
Chào các bác em thử làm nhưng ko lấy được đường dẫn ảnh giờ em phải làm sao, đây là code của em các bác giúp em với ạ
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text.RegularExpressions;
using System.Net;
using System.IO;

public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ExtractContent("http://www.tripadvisor.com/Hotel_Review-g293924-d1891647-Reviews-Hanoi_Happy_Hotel-Hanoi.html", "<div class=\"basic_review \">((.|\\n)*?)</div> ", 1);
}
private string LoadHTML(string link)
{
try
{
// Tạo yêu cầu.
WebRequest obj = WebRequest.Create(link);
// Lấy đáp ứng. công việc này sẽ lấy nội dung trang web về
WebResponse webRespone = obj.GetResponse();
// Đọc đáp ứng (dạng stream).
StreamReader sr = new StreamReader(webRespone.GetResponseStream());
string result = sr.ReadToEnd();
return result;
}
catch
{
return null;
}
}
public string ExtractContent(string url, string Dieukien, int Nhom)
{
string content = LoadHTML(url);
string extractedContent = "";
if (content != null)
{
Regex regEx = new Regex(Dieukien, RegexOptions.IgnoreCase);
Match match = regEx.Match(content);
while (match != null && match.Success && match.Groups[Nhom].Success)
{
ltr.Text += match.Groups[Nhom].Value +"<br />";
match = match.NextMatch();
}
}
return extractedContent;
}
}