public List <MonsterPart> GetParts(IDocument page, int monster) { List <MonsterPart> parts = new List <MonsterPart>(); var part_rows = page.QuerySelectorAll(".col-lg-5 tbody tr"); foreach (var row in part_rows) { var tds = row.QuerySelectorAll("td"); MonsterPart part = new MonsterPart() { part_name = tds[0].TextContent, stagger_value = Convert.ToInt32(tds[1].TextContent), monsterid = monster }; if (tds[3].TextContent.Contains("R")) { part.extract_color = "red"; } else if (tds[3].TextContent.Contains("O")) { part.extract_color = "orange"; } else { part.extract_color = "white"; } try { parts.Add(part); } catch (SQLiteException ex) { Console.WriteLine(ex.ToString()); } } return(parts); }
public async Task <List <MonsterDrop> > GetDrops(IDocument page, int monster, SQLiteAsyncConnection db) { List <MonsterDrop> drops = new List <MonsterDrop>(); var table_wrappers = page.QuerySelectorAll(".col-lg-6"); foreach (var wrapper in table_wrappers) { string rank = wrapper.QuerySelector("h5").TextContent; string currentSource = ""; foreach (var tr in wrapper.QuerySelectorAll("tr").Where(t => t.ClassName != "table-active")) { if (tr.FirstElementChild.ClassName == "vertical-align") { currentSource = tr.FirstElementChild.TextContent.Trim(); } else { var tds = tr.QuerySelectorAll("td"); var drop_item = await db.QueryAsync <Item>("select * from Items where item_name = ?", ((IHtmlAnchorElement)tds[1].FirstElementChild).TextContent); MonsterPart part = new MonsterPart(); // Make sure it's not adding the same carve/capture multiple time. var tempp = await db.QueryAsync <MonsterPart>("SELECT * FROM MonsterParts WHERE monsterid = ?", monster); foreach (var monpart in tempp) { if (currentSource == monpart.part_name) { part = monpart; break; } } if (part.part_name == null) { part.monsterid = monster; part.part_name = currentSource; await db.InsertAsync(part); } Regex intsOnly = new Regex(@"[^\d]"); var part_wrap = await db.QueryAsync <MonsterPart>("select * from MonsterParts where id = ?", part.id); string quantity = ""; if (tds[1].TextContent.Any(char.IsDigit)) { quantity = intsOnly.Replace(tds[1].TextContent.Trim(), ""); } else { quantity = "1"; } MonsterDrop drop = new MonsterDrop() { itemid = drop_item[0].id, monsterid = monster, sourceid = part_wrap[0].id, rank = rank, drop_chance = Convert.ToInt32(intsOnly.Replace(tds[2].TextContent.Trim(), "")), quantity = Convert.ToInt32(intsOnly.Replace(quantity, "")) }; drops.Add(drop); } } } return(drops); }