public void ParseItem(IResponse response) { var itemLoader = ItemLoaderFactory.GetItemLoader <JobItem>(response); itemLoader.BeforeValueSetting += ItemLoader_BeforeValueSetting; itemLoader.AddFieldMapping("Title", "css:.title-info h1::attr(text)"); itemLoader.AddFieldMapping("Title", "css:.job-title h1::attr(text)"); itemLoader.AddFieldMapping("Firm", "css:.title-info h3 a::attr(text)"); itemLoader.AddFieldMapping("Firm", "css:.title-info h3::attr(text)"); itemLoader.AddFieldMapping("Firm", "css:.title-info h3"); itemLoader.AddFieldMapping("Firm", "css:.job-title h2::attr(text)"); itemLoader.AddFieldMapping("Salary", "css:.job-main-title p::attr(text)"); itemLoader.AddFieldMapping("Salary", "css:.job-main-title strong::attr(text)"); itemLoader.AddFieldMapping("Salary", "css:.job-item-title p::attr(text)"); itemLoader.AddFieldMapping("Salary", "css:.job-item-title"); itemLoader.AddFieldMapping("Time", "css:.job-title-left time::attr(title)"); itemLoader.AddFieldMapping("Time", "css:.job-title-left time::attr(text)"); itemLoader.AddFieldMapping(u => u.Location, "css:.basic-infor span a::attr(text)"); itemLoader.BeforeValueSetting += (sender, e) => e.Item.URL = response.URL; var item = itemLoader.LoadItem(); Console.WriteLine(item.Firm); }
public void Parse(IResponse response) { //response.CssSelector(".job-info h3 a"); var MockItemLoader = ItemLoaderFactory.GetItemLoader <MockItem>(response); MockItemLoader.BeforeValueSetting += MockItemLoader_BeforeValueSetting; MockItemLoader.AddFieldMapping("MockValue", "MockValue Mapped!"); MockItemLoader.AddFieldMapping(u => u.MockValue2, "MockValue2 Mapped!"); MockItemLoader.LoadItem(); }
private void ParseItem(IResponse response) { var itemLoader = ItemLoaderFactory.GetItemLoader <House>(response); itemLoader.AddFieldMapping(u => u.Title, "css:.title h1::attr(title)"); itemLoader.AddFieldMapping(u => u.SubTitle, "css:.title div::attr(title)"); itemLoader.AddFieldMapping(u => u.TotalPrice, "css:.price span::attr(text)"); itemLoader.AddFieldMapping(u => u.UnitPrice, "css:.unitPrice span::attr(text)"); itemLoader.AddFieldMapping(u => u.Size, "css:.area .mainInfo div::attr(text)"); itemLoader.AddFieldMapping(u => u.CommunityName, "css:.communityName .info a::attr(text)"); itemLoader.AddFieldMapping(u => u.Room, "css:.room .mainInfo div::attr(text)"); var item = itemLoader.LoadItem(); Console.Write($"{item.Title},{item.SubTitle},{item.TotalPrice},{item.UnitPrice},{item.Size},{item.Room},{item.CommunityName}"); Console.WriteLine(); }