我想抓取京东的商品信息例如 http://www.360buy.com/product/503023.html现在我的代码如下
WebClient client = new WebClient();
byte[] byteArr = client.DownloadData(TextBox1.Text.Trim());
string htmlStr = System.Text.Encoding.GetEncoding("gb2312").GetString(byteArr);
MatchCollection matches = Regex.Matches(htmlStr, @"(?is)<div class=""mc fore tabcon"">(.*?)</div>"); foreach (Match match in matches)
Response.Write(match.Groups[1].Value);
现在的问题是 我只能抓取一部分 不能完全获取 div class="mc fore tabcon" 里面的内容我这个正则是不是有问题? 求教了。
WebClient client = new WebClient();
byte[] byteArr = client.DownloadData(TextBox1.Text.Trim());
string htmlStr = System.Text.Encoding.GetEncoding("gb2312").GetString(byteArr);
MatchCollection matches = Regex.Matches(htmlStr, @"(?is)<div class=""mc fore tabcon"">(.*?)</div>"); foreach (Match match in matches)
Response.Write(match.Groups[1].Value);
现在的问题是 我只能抓取一部分 不能完全获取 div class="mc fore tabcon" 里面的内容我这个正则是不是有问题? 求教了。
如果你的<div>里面有嵌套div了 那很遗憾 你肯定不能全部获取
解决方案就是使用平衡组,或者是使用贪婪匹配