banner

[Rule] Rules  [Home] Main Forum  [Portal] Portal  
[Members] Member Listing  [Statistics] Statistics  [Search] Search  [Reading Room] Reading Room 
[Register] Register  
[Login] Loginhttp  | https  ]
 
Forum Index Thảo luận hệ điều hành Windows Lấy tự động cập nhật giá vàng, ngoại tệ  XML
  [Programming]   Lấy tự động cập nhật giá vàng, ngoại tệ 05/07/2008 08:33:07 (+0700) | #1 | 139973
[Avatar]
sunrise_vn
Member

[Minus]    0    [Plus]
Joined: 10/03/2008 21:06:26
Messages: 179
Location: Kim Quyên's heart
Offline
[Profile] [PM]
Bạn nào có code lấy giá vàng, ngoại tệ bằng ASP.Net share mình với.
Cám ơn!
What is love?
What real love can do?
[Up] [Print Copy]
  [Question]   Re: Lấy tự động cập nhật giá vàng, ngoại tệ 05/07/2008 21:38:13 (+0700) | #2 | 140039
[Avatar]
phamtungvnp
Member

[Minus]    0    [Plus]
Joined: 24/11/2007 01:52:42
Messages: 1
Offline
[Profile] [PM]
Bạn định lấy tỉ giá trong code hay = javascript?
Tui có đoạn code phân tích dạng html rồi lấy thông tin vào file XML nhưng mỗi lần chạy lại phải refresh.Và nó hơi cứng chỉ áp dụng lấy cho 1 trang cụ thể thôi sang trang khác là chít liền.Bạn nào biết làm cách nào mà khi up lên server ko cần refresh nó vẫn chạy theo một thời gian nhất định không bảo tui với.
--Get HTML
public static string GetHtmlFromUrl(string url)
{
if (string.IsNullOrEmpty(url))
throw new ArgumentNullException("url", "Parameter is null or empty");

string html = "";
//HttpWebRequest request = GenerateHttpWebRequest(url);
WebRequest request = WebRequest.Create(url);
// If required by the server, set the credentials.
//request.Credentials = CredentialCache.DefaultCredentials;
//request.Timeout = 8000;
try
{
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusDescription == "OK")
{
Stream responseStream = response.GetResponseStream();
using (StreamReader reader = new StreamReader(responseStream, Encoding.UTFsmilie
{
html = reader.ReadToEnd();
}
}
else
{
html = "error";
}
}
catch (WebException ex)
{
// Response.Write("Xin lỗi hiện tại hệ thống không kết nối được với máy chủ cung cấp tin tức.");
}
return html;
}//Get code html

--lấy phần html chứa giá vàng
public static void getgiavang(string html, string dir)//Tách lấy từng mã tỉ giá một từ table vừa phân tích được
{
string src = gettablegiavang(GetHtmlFromUrl(html));
src = src.ToLower();
string kq = "";
string loai, mua, ban, tam1, tam2, tam3;
loai = ""; mua = ""; ban = ""; tam1 = ""; tam2 = ""; tam3 = "";
int x1, x2, x3; x1 = 0; x2 = 0; x3 = 0;
int i = 0;
x1 = src.IndexOf("<tr");
//bỏ tr đầu tiên tìm thấy
if (x1 != -1)
{
x2 = src.IndexOf("</tr", x1);
if (x2 != -1)
{
src = src.Substring(x2 + 5);
}
}
string file = "giavang.xml";
toolwebservices.del_create_file(dir, file);
while (i < src.Length)
{
x1 = src.IndexOf("</tr>", 0);
if (x1 != -1)
{
tam1 = src.Substring(0, x1);
src = src.Substring(x1 + 5);
int j1 = 0;
int j2 = 0;
while (j1 < tam1.Length)
{
x2 = tam1.IndexOf("</font>");
if (x2 != -1)
{
j1 = j1 + 1;
tam2 = tam1.Substring(0, x2);
tam1 = tam1.Substring(x2 + 7);
j2 = tam2.LastIndexOf(">");
if (j2 != -1)
{
//dia diem
if (j1 ==1)
{
loai = tam2.Substring(j2 + 1);
}
//kq = kq + "," + diadiem;
if (j1 == 2)
{
mua = tam2.Substring(j2 + 1);
}
if (j1 == 3)
{
ban = tam2.Substring(j2 + 1);
}
}
}
else
{
j1 = tam1.Length;
break;
}
}
toolwebservices.WriteXMLgiavang(dir,loai,mua,ban);
}
else
{
i = src.Length;
break;
}
}
}
public static string gettablegiavang(string html)
{
string src = html.ToLower();
int x1, x2, x3;
x1 = 0; x2 = 0; x3 = 0;
string tam = "";
string temp1 = "";
string kq = "";
x1 = src.IndexOf("gi tham khảo)", 0);
if (x1 != -1)
{
tam = src.Substring(x1);
x2 = tam.IndexOf("<table");
if (x2 != -1)
{
x3 = tam.IndexOf("</table>", x2);
kq = tam.Substring(x2, x3 + 8 - x2);
}

}
else
{
kq = "0";
}

return kq;
}
//Tách lấy table bao quanh phần thông tin giá vàng

--write file xml
public static void WriteXMLgiavang(string dir,string loai,string mua,string ban)
{
try
{

//pick whatever filename with .xml extension
//XmlTextWriter xmlWRITER = new XmlTextWriter ( "C:\\writeEmployeeRecordInXML1.xml" , null );
string filename = dir + "/" + "giavang.xml";
XmlDocument xmlDoc = new XmlDocument();
try
{
xmlDoc.Load(filename);
}
catch (System.IO.FileNotFoundException)
{
//if file is not found, create a new xml file
XmlTextWriter xmlWriter = new XmlTextWriter(filename, System.Text.Encoding.UTF8);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteProcessingInstruction("xml", "version='1.0' encoding='UTF-8'");
xmlWriter.WriteStartElement("Root");

xmlWriter.Close();
xmlDoc.Load(filename);
}
XmlNode root = xmlDoc.DocumentElement;
XmlElement childNode = xmlDoc.CreateElement("Item");
XmlElement childNode1 = xmlDoc.CreateElement("Loai");
XmlElement childNode2 = xmlDoc.CreateElement("Mua");
XmlElement childNode3 = xmlDoc.CreateElement("Ban");

root.AppendChild(childNode);
childNode.AppendChild(childNode1);
childNode.AppendChild(childNode2);
childNode.AppendChild(childNode3);

//gan gia tri cho cac thuoc tinh
XmlText textNode1 = xmlDoc.CreateTextNode(loai);
childNode1.AppendChild(textNode1);
XmlText textNode2 = xmlDoc.CreateTextNode(mua);
childNode2.AppendChild(textNode2);
XmlText textNode3 = xmlDoc.CreateTextNode(ban);
childNode3.AppendChild(textNode3);
xmlDoc.Save(filename);
}
catch (Exception ex)
{
// WriteError(ex.ToString());

}
}

[Up] [Print Copy]
  [Question]   Re: Lấy tự động cập nhật giá vàng, ngoại tệ 06/07/2008 21:41:15 (+0700) | #3 | 140162
[Avatar]
sunrise_vn
Member

[Minus]    0    [Plus]
Joined: 10/03/2008 21:06:26
Messages: 179
Location: Kim Quyên's heart
Offline
[Profile] [PM]
Mình định update giá cả trông MasterPage. Tất cả bằng code. Cảm ơn bạn.
What is love?
What real love can do?
[Up] [Print Copy]
  [Question]   Re: Lấy tự động cập nhật giá vàng, ngoại tệ 19/07/2008 13:41:54 (+0700) | #4 | 142278
[Avatar]
KoL
Member

[Minus]    0    [Plus]
Joined: 27/06/2006 02:50:18
Messages: 2
Offline
[Profile] [PM]
Cái này tìm 1 trang nào đó cập nhật nhanh uy tín chút. down cả nội dung trang web ( trang có chứa giá cả ) đấy vào 1 file text. Rồi tìm, cắt....xâu gì gì đó là ok mà.
[Up] [Print Copy]
  [Question]   Re: Lấy tự động cập nhật giá vàng, ngoại tệ 01/01/2009 09:20:05 (+0700) | #5 | 164756
quainhankid
Member

[Minus]    0    [Plus]
Joined: 13/09/2007 16:58:02
Messages: 1
Offline
[Profile] [PM]
toolwebservices.del_create_file(dir, file);  

Cái hàm này ở đâu bạn
[Up] [Print Copy]
  [Question]   Re: Lấy tự động cập nhật giá vàng, ngoại tệ 01/01/2009 11:24:14 (+0700) | #6 | 164770
mrhoangha
Member

[Minus]    0    [Plus]
Joined: 31/07/2008 18:40:28
Messages: 484
Offline
[Profile] [PM] [Yahoo!]
Em có 1 sỗ links có lẽ có ích nè:

Chứng Khoán HOSE
http://vnexpress.net/User/ck/hcms/HCMStockSmall.asp
Chứng khoán HaSTC
http://vnexpress.net/User/ck/hns/HNStockSmall.asp
Ngoại tệ
http://www.vietstock.com.vn/Transweb/tygia.htm
Vàng
http://www.vietstock.com.vn/Transweb/giavang.htm
[Up] [Print Copy]
  [Programming]   Lấy tự động cập nhật giá vàng, ngoại tệ 13/07/2011 08:25:48 (+0700) | #7 | 243414
vn.cuongquoc.hue
Member

[Minus]    0    [Plus]
Joined: 30/11/2009 09:06:36
Messages: 1
Offline
[Profile] [PM]
Mình có đoạn này dễ dùng hơn nè. Cái này lấy DL từ ngân hàng eximbank

<div style="overflow-x: auto;">

<iframe src="http://www.eximbank.com.vn/WebsiteExrate1/exchange.aspx" marginheight="5px"
marginwidth="0" scrolling="no" width="300px" frameborder="0" height="245px"></iframe>

<iframe src="http://www.eximbank.com.vn/WebsiteExrate1/gold.aspx" marginheight="0"
marginwidth="0" scrolling="no" width="300px" frameborder="0" height="100px"></iframe>
</div>
[Up] [Print Copy]
  [Programming]   Re: Lấy tự động cập nhật giá vàng, ngoại tệ 13/12/2012 21:08:39 (+0700) | #8 | 271820
[Avatar]
abonlahor
Member

[Minus]    0    [Plus]
Joined: 28/11/2009 00:50:46
Messages: 16
Offline
[Profile] [PM]

phamtungvnp wrote:

toolwebservices.del_create_file(dir, file);

 

hàm này nằm ở đâu vậy bạn?
[Up] [Print Copy]
[digg] [delicious] [google] [yahoo] [technorati] [reddit] [stumbleupon]
Go to: 
 Users currently in here 
1 Anonymous

Powered by JForum - Extended by HVAOnline
 hvaonline.net  |  hvaforum.net  |  hvazone.net  |  hvanews.net  |  vnhacker.org
1999 - 2013 © v2012|0504|218|