Diễn đàn    ASP.NET & Sharepoint MOSS, WSS 2007    Share code craw data C#

Thành viênTrả lời
kimlong008


25  bài
20-2-2011 15:7:11
vì là lấy dữ liệu nên tôi làm 1 bài cho trọn bộ, cách craw cuối cùng

gọi hàm thư viện :

Mã:
using System.Net;
using System.IO;


Đọc hoặc load toàn bộ nội dung HTML web site cần lấy :

Mã:
System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("http://www.kitco.com/pop_windows/exchdetails.html");
myRequest.MaximumAutomaticRedirections = 1;
myRequest.AllowAutoRedirect = true;
System.Net.HttpWebResponse myResponse = (System.Net.HttpWebResponse)myRequest.GetResponse();
Stream resStream = myResponse.GetResponseStream();
StreamReader reader = new StreamReader(resStream);
string readstring = reader.ReadToEnd();


Phân tích nội dung và Regex cần lấy :


Mã:
int tableIndex = readstring.IndexOf("Exchange Rate change from last 24 hours");
readstring = readstring.Substring(tableIndex, readstring.Length - tableIndex);
// xoa mat dong RegexOptions.Compiled trong dong ben duoi
readstring = System.Text.RegularExpressions.Regex.Replace(readstring, @"\n", "");
readstring = System.Text.RegularExpressions.Regex.Match(readstring, @"<table.*?<\/table>").Value;

this.Literal2.Text = readstring;


code demo tên file là Craw3.aspx : DOWNLOAD http://www.4shared.com/file/mAiQHl9W/khotienvn.html

Xem thêm chi tiết bài viết tại đây : http://khotien.vn/diendan/default.aspx?g=posts&m=1380
 
khanhjin@gmail.com

Một ngày tình cờ trên đường phố tôi có bàn chân em ...
36  bài
21-2-2011 11:18:16
Code hay đấy
---
Đang yêu
 
nguyenvuit

Thích Java
25  bài
23-2-2011 19:41:46
Cái này nó cần phải hiểu biết bên Regex,mà chủ đề này của bạn hơi cũ rùi(Cái này bạn làm giống cái Load giá ngoại tệ của HaNamclien)
 
seekill


20  bài
10-3-2011 14:57:37
Cái này thì theo mình k fai là crawl mà đơn giản nó chỉ get text về và xử lý thôi chứ nhỉ :-?
 

Chủ đề gần đây :

Cùng loại :

Tên file Mô tả chi tiết Ngày
NWeb.zip (1) Module đơn giản Newsweb trên Dotnetnuke v10.x.x.x10/18/2025 8:08:11 AM
vspforum.zip (11) Ma nguon vspforum ngay xua4/18/2023 6:38:37 AM
pdfjs.rar (2) pdfjs 2017 : hiển thị tốt trên iphone 11, 12, 13 không lỗi, bản 2012 sẽ lỗi trên iphone6/21/2022 11:52:48 AM
pdfjs2.rar (2) Xem file pdf bằng viewer.hml cua pdfjs (thư viện chuẩn mozilla) 2012. https://mozilla.github.io/pdf.js/getting_started/#download có thể download bản prebuild tại đây6/21/2022 11:52:04 AM
runner.zip (0) using three.js, orbitcontrol to view an object move random on map. Di chuyển 1 đồ vật ngẫu nhiên trên bản đồ, sử dụng với demo nhân viên di chuyển trong văn phòng. Toàn js download về là chạy12/5/2019 5:55:14 PM
gmap.zip (1) google map + marker7/17/2019 2:25:05 PM
vinsmarthomeservice.zip (1) java post json to api, use AsyncTask, event listener7/9/2019 5:00:10 PM
fblogin.zip (0) Login facebook bang javascript SDK7/9/2019 9:16:37 AM
autocomplete-location.zip (2) autocomplete location geo from google place, html + js7/4/2019 4:37:55 PM
WebAPI.zip (8) api for android access db (v1.0.0)7/4/2019 9:14:17 AM