private void dataGridViewURL_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { ViewImageForm vif = new ViewImageForm(); ViewDataGridForm vdgf = new ViewDataGridForm(); //var url = vdgf.dataGridViewURL.CurrentRow.Cells[1].Value.ToString(); //using (var client = new HttpClient()) //{ // var req = client.GetAsync(url).ContinueWith(res => // { // var result = res.Result; // if (result.StatusCode == System.Net.HttpStatusCode.OK) // { // var readData = result.Content.ReadAsStringAsync(); // readData.Wait(); // var readStream = readData.Result; // var image = Image.FromStream(readStream); // vif.pictureBox1.Image = image; // } // }); //} vif.Show(); }
private static async Task GetContent(HttpClient httpClient, string url, string nodes, string singleNode) { MainForm mf = new MainForm(); ViewHtmlForm vhtmlf = new ViewHtmlForm(); ViewDataGridForm vdgf = new ViewDataGridForm(); try { HttpResponseMessage response = await httpClient.GetAsync(url); response.EnsureSuccessStatusCode(); // Высвобождает ресурсы если соеденение не удалось var html = await response.Content.ReadAsStringAsync(); vhtmlf.TextBoxViewHtml = html; vhtmlf.Show(); vdgf.Show(); var htmlDoc = new HtmlAgilityPack.HtmlDocument(); htmlDoc.LoadHtml(html); int count = 0; try { var posts = htmlDoc.DocumentNode.SelectNodes(nodes); foreach (var post in posts) { count++; var poster = post.SelectSingleNode(singleNode)?.GetAttributeValue("src", "").Trim(); mf._entries.Add(new EntryModel { Number = count, PosterUrl = "https://yummyanime.club" + poster }); vdgf.dataGridViewURL.Rows.Add(count, "https://yummyanime.club" + poster); } } catch (NullReferenceException exc) { MessageBox.Show($"{exc.Message}", "Exception Caught", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } catch (System.Xml.XPath.XPathException exc) { MessageBox.Show($"{exc.Message}", "Exception Caught", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } } catch (HttpRequestException exc) { MessageBox.Show($"{exc.Message}", "Exception Caught", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly); } }