public List <MovieBasic> Query(string keyword) { Uri u = urlCombine(keyword); HtmlDocument doc = new HtmlDocument(); wc.Headers.Set("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.2; zh-TW; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5"); wc.Headers.Set("Referer", "http://aventertainments.com/Main.aspx?languageID=2"); wc.Headers.Set("Content-Type", "application/x-www-form-urlencoded"); string htmlString = wc.GetHTML(u); doc.LoadHtml(htmlString); var listItems = doc.DocumentNode.SelectNodes("//table[@id='ctl00_ContentPlaceHolder1_Rows2Items1_MyList']/tr/td[@valign='top']/table"); List <MovieBasic> l = new List <MovieBasic>(); if (listItems == null) { return(l); } foreach (var item in listItems) { var title = item.ChildNodes["tr"].ChildNodes["td"].ChildNodes["h4"].InnerText; //listItems[0].ChildNodes["table"].ChildNodes["tr"].ChildNodes["td"].ChildNodes["h4"].InnerText; title = title.Trim(" ".ToArray()); var img_s = item.ChildNodes["tr"].ChildNodes["td"].ChildNodes["div"].ChildNodes["a"].ChildNodes["img"].Attributes["src"].Value; var actor = item.ChildNodes["tr"].ChildNodes["td"].ChildNodes["a"].InnerText; var maker = item.ChildNodes["tr"].ChildNodes["td"].Elements("a").ElementAt(1).InnerText; var itemURL = item.ChildNodes["tr"].ChildNodes["td"].ChildNodes["h4"].ChildNodes["a"].Attributes["href"].Value; var label = item.ChildNodes["tr"].ChildNodes["td"].InnerText; int st = label.IndexOf("商品番号:") + 5; int ed = label.IndexOf("発売日"); label = label.Substring(st, ed - st).Trim().Trim(" ".ToArray()); var _actorList = new List <string>(); _actorList.Add(actor); MovieBasic mb = new MovieBasic() { Title = title, Img_s = img_s, Actor = _actorList, ItemURL = itemURL, Label = label, Maker = maker }; l.Add(mb); } return(l); //wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); //wc.Headers.Add(System.Net.HttpRequestHeader.Referer, "https://www.aventertainments.com/login.aspx?languageID=1"); //NameValueCollection nvc = new NameValueCollection(); //nvc.Add("ctl00$ContentPlaceHolder1$uid","*****@*****.**"); //nvc.Add("ctl00$ContentPlaceHolder1$passwd", "177991"); //wc.UploadData("https://www.aventertainments.com/login.aspx?languageID=1", "POST", nvc); }
private List <MovieBasic> PageParse(Uri u) { HtmlAgilityPack.HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(wc.GetHTML(u)); //doc.DocumentNode.SelectNodes("//li[@class='saledate']/span")[3].InnerText var listitems = doc.DocumentNode.SelectNodes("//div[@id='listitem']/table/tr/td/div[@class='data']/ul[1]/li[2]"); var htmnode = doc.DocumentNode.SelectSingleNode("//div[@class='autopagerize_page_element']"); if (htmnode == null) { //查无此片 return(new List <MovieBasic>()); } string htm = htmnode.InnerHtml; List <MovieBasic> l = new List <MovieBasic>(); //<div class="autopagerize_page_element"> int cou = doc.DocumentNode.SelectNodes("//div[@id='itemd']").Count; for (int i = 0; i < cou; i++) { string n_title = doc.DocumentNode.SelectNodes("//div[@id='itemd']//h2/a")[i].InnerText; n_title = Tools.RemoveInvalidChars(n_title); string n_itemURL = "http://" + u.Host + doc.DocumentNode.SelectNodes("//div[@id='itemd']//h2/a")[i].Attributes["href"].Value; string n_date = doc.DocumentNode.SelectNodes("//div[@id='itemd']//span")[i].InnerText.Trim(); var datanode = doc.DocumentNode.SelectNodes("//div[@class='data']")[i]; HtmlDocument docData = new HtmlDocument(); docData.LoadHtml(datanode.InnerHtml); int k = docData.DocumentNode.SelectNodes("//ul[1]/li").Count; string n_actor = string.Empty; List <string> actors = new List <string>(); if (k > 1) { for (int j = k; j > 1; j--) { n_actor = docData.DocumentNode.SelectNodes("//ul[1]/li[" + j + "]")[0].InnerText.Trim(); actors.Add(n_actor); } } string n_maker = docData.DocumentNode.SelectSingleNode("//ul[2]/li[2]").InnerText.Trim(); string n_company = docData.DocumentNode.SelectSingleNode("//ul[3]/li[2]").InnerText.Trim(); var n_ticai_node = docData.DocumentNode.SelectSingleNode("//ul[4]/li[2]"); string n_ticai; if (n_ticai_node == null) { n_ticai = string.Empty; } else { n_ticai = n_ticai_node.InnerText.Trim(); } string s_img = doc.DocumentNode.SelectNodes("//div[@id='listitem']/table/tr/td/div/a/img")[i].Attributes["src"].Value; MovieBasic mb = new MovieBasic() { Title = n_title, ItemURL = n_itemURL, Img_s = s_img, Actor = actors, Maker = n_company, Label = n_ticai }; l.Add(mb); } return(l); }