先在project>add reference 加上HtmlAgilityPack.dll
再配合firebug 的XPATH
//以apple store iphone 4s 為例
string str = "http://store.apple.com/hk/browse/home/shop_iphone/family/iphone/iphone4s";
try
{
HttpWebResponse
httpWebResponse = httpWebRequest.GetResponse() as
HttpWebResponse;
Stream
stream = httpWebResponse.GetResponseStream();
StreamReader
reader = new StreamReader(stream,
Encoding.UTF8);
string
s = reader.ReadToEnd();
reader.Close();
stream.Close();
httpWebResponse.Close();
HtmlAgilityPack.HtmlDocument htmlDoc = new
HtmlAgilityPack.HtmlDocument();
htmlDoc.LoadHtml(s);
//16GB
32GB 64GB 的運送時間XPATH
HtmlNode
anchors = htmlDoc.DocumentNode.SelectSingleNode(
"/html/body/div[2]/div[3]/div/div[2]/div[2]/div[3]/ul/li/label/span/span[3]/span");
HtmlNode
anchors32 = htmlDoc.DocumentNode.SelectSingleNode(
"/html/body/div[2]/div[3]/div/div[2]/div[2]/div[3]/ul/li[2]/label/span/span[3]/span");
HtmlNode
anchors64 = htmlDoc.DocumentNode.SelectSingleNode(
"/html/body/div[2]/div[3]/div/div[2]/div[2]/div[3]/ul/li[3]/label/span/span[3]/span");
//output
txtStatus.Text += anchors.InnerText + " " + anchors32.InnerText + " " + anchors64.InnerText + " ";
}
catch
(WebException web)
{
沒有留言:
張貼留言