110,502
社区成员
发帖
与我相关
我的任务
分享
HtmlWeb htmlWeb = new HtmlWeb();
HtmlDocument htmlDoc = htmlWeb.Load(@"http://www.suning.com/emall/prd_10052_10051_-7_1821594_.html");
Console.WriteLine(htmlDoc.DocumentNode.SelectSingleNode(@"//input[@id='ga_mainTopCategorytBean_description_name']").Attributes["value"].Value);
Console.WriteLine(htmlDoc.DocumentNode.SelectSingleNode(@"//input[@id='ga_itemDataBean_description_name']").Attributes["value"].Value);
Console.WriteLine(htmlDoc.DocumentNode.SelectSingleNode(@"//div[@class='btn_box']//img").Attributes["src"].Value);
string s = @"<div class=""btn_box"">
<ul>
<li class=""cur""><img src=""http://image.suning.cn/content/catentries/00000000010229/000000000102292839/fullimage/000000000102292839_1.jpg"" src2=""http://image.suning.cn/content/catentries/00000000010229/000000000102292839/fullimage/000000000102292839_1f.jpg"" alt=""""></li>
</div>";
Match match = Regex.Match(s, @"(?is)<div class=""btn_box"">\s*<ul>\s*<li[^>]+>\s*<img src=""([^""]+)""\s*src2=");
Console.Write(match.Groups[1].Value);
string s = @"<!-- 参数名称 -->
<td width=""19%"" class=""a1"">
<div class=""Imgpip"">
<span>品牌:</span>
</div>
</td>
<!-- 参数值 -->
<td width=""72%"">联想</td>
<td width=""9%"">
<a href=""javascript:void(0)"" class=""erro_recovery hide"">纠错</a>
</td>
</tr>";
Match match = Regex.Match(s, @"(?is)<!-- 参数名称 -->.+?<span>(.+?)</span>.+?<!-- 参数值 -->\s*<td[^>]*>(.+?)</td>");
Console.Write(match.Groups[1].Value + match.Groups[2].Value);
string s = @"<input type=""hidden"" value=""联想笔记本IdeaPadY471AI52450M4G500R7B(BK)CN"" id=""ga_itemDataBean_description_name""/>
<input type=""hidden"" value=""笔记本"" id=""ga_itemDataBean_category_description_name""/>";
string id = "ga_itemDataBean_category_description_name";
Match match = Regex.Match(s, string.Format(@"<input.+?value=""(?<value>[^""]+)"" id=""{0}""\s*/>", id));
Console.Write(match.Groups["value"].Value);