如果有人可以提供帮助,我将不胜感激!我正在尝试解析 Groupon 网站http://www.groupon.com/browse/chicago?category=activities-and-nightlife的以下页面
var webGet = new HtmlWeb();
var deal1 = webGet.Load("http://www.groupon.com/browse/chicago?category=activities-and-nightlife");
我想获得每笔交易的全部内容(即提供折扣)
HtmlNodeCollection content_block = deal1.DocumentNode.SelectNodes("//div[@class = 'deal-list-tile grid_5_third']");
然后从每个块中我想获得标题、公司名称、位置和价格。
foreach(HtmlNode node in content_block)
{
string title2 = node.SelectSingleNode("//div[@class = 'deal-title js-permalink']").InnerText;
string country2 = node.SelectSingleNode("//p[@class = 'merchant-name']").InnerText;
string location2 = node.SelectSingleNode("//p[@class = 'location']").InnerText;
string price2 = node.SelectSingleNode("//div[@class = 'price']/span").InnerText;
}
在这里我感到困惑,我需要将有关交易的所有信息写入
DbSet<Deal> Deals
,但即使我尝试显示内容,因为ViewBag.Message = title + country + location + price;
我得到 System.NullReferenceException: Object reference not set to an instance of an object in line with content_block
。
我做错了什么=(提前谢谢!