using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Net; using System.IO; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { WebRequest myRequest = WebRequest.Create(@"https://tw.stock.yahoo.com/q/bc?s=1506"); //Method選擇GET myRequest.Method = "GET"; //取得WebRequest的回覆 WebResponse myResponse = myRequest.GetResponse(); //Streamreader讀取回覆 StreamReader sr = new StreamReader(myResponse.GetResponseStream()); //將全文轉成string string result = sr.ReadToEnd(); //關掉StreamReader sr.Close(); //關掉WebResponse myResponse.Close(); System.Console.Write(result); Console.ReadLine(); //搜尋頭尾關鍵字, 搜尋方法見後記(1) //int first = result.IndexOf("美元 = <em>"); //int last = result.LastIndexOf("</em> 新台幣"); //減去頭尾不要的字元或數字, 並將結果轉為string. 計算方式見後記(2) //string HTMLCut = result.Substring(first + 9, last - first - 9); //txtRate.Text = HTMLCut; } } }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more