Espero que alguien pueda ayudar ya que he pasado años tratando de resolver esto. Estoy utilizando el paquete de agilidad para extraer datos de una tabla y colocarlos en una cuadrícula de datos (la cuadrícula de datos no es importante, solo la estoy usando para ver si la extracción funciona). De todos modos en la primera columna de la tabla se contienen imágenes en miniatura. Puedo extraer todo el texto usando el código de abajo, pero no sé cómo extraer las imágenes de la primera columna ... ¿Puede alguien ayudarme?
PS He guardado la página web como un archivo MHL porque no pude extraer ningún dato directamente de ella. Creo que tiene algo que ver con la seguridad / credenciales del sitio. No sé si he hecho las cosas más fáciles o más difíciles para mí.
Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
' '' original cods ***************************************
Dim Web As New HtmlAgilityPack.HtmlWeb
Dim Doc As New HtmlAgilityPack.HtmlDocument
Dim RowCount As Integer = 1
' Doc = Web.Load("https://firefly.cardinalnewman.ac.uk/home/my")
Doc.Load("E:\table.mht")
Dim tables As HtmlAgilityPack.HtmlNodeCollection = Doc.DocumentNode.SelectNodes("//table")
Dim img As HtmlAgilityPack.HtmlNodeCollection = Doc.DocumentNode.SelectNodes("//table")
Dim Links As HtmlAgilityPack.HtmlNodeCollection = Doc.DocumentNode.SelectNodes("//table")
Dim rows As HtmlAgilityPack.HtmlNodeCollection = tables(0).SelectNodes("//*[@id=HomeMyStudents]")
For Each table As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes("//*[@id='HomeMyStudents']/tbody/tr['RowCount']/td[1]")
RowCount = RowCount + 1
DGV.Rows.Add(Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
Next
RowCount = 0
For Each table As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes("//*[@id='HomeMyStudents']/tbody/tr['RowCount']/td[2]")
RowCount = RowCount + 1
' DGV.Rows(RowCount).Cells(1).Value = somehow insert image
' this is the section where I need to grab the image in each cell and either save or place in my datagrid
Next
RowCount = 0
For Each table As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes("//*[@id='HomeMyStudents']/tbody/tr['RowCount']/td[3]")
RowCount = RowCount + 1
DGV.Rows(RowCount).Cells(2).Value = table.InnerText
Next
RowCount = 0
For Each table As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes("//*[@id='HomeMyStudents']/tbody/tr['RowCount']/td[4]")
RowCount = RowCount + 1
DGV.Rows(RowCount).Cells(3).Value = table.InnerText
Next
RowCount = 0
For Each table As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes("//*[@id='HomeMyStudents']/tbody/tr['RowCount']/td[5]")
RowCount = RowCount + 1
DGV.Rows(RowCount).Cells(4).Value = table.InnerText
Next
RowCount = 0
For Each table As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes("//*[@id='HomeMyStudents']/tbody/tr['RowCount']/td[6]")
RowCount = RowCount + 1
DGV.Rows(RowCount).Cells(5).Value = table.InnerText
Next
RowCount = 0
For Each table As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes("//*[@id='HomeMyStudents']/tbody/tr['RowCount']/td[7]")
RowCount = RowCount + 1
DGV.Rows(RowCount).Cells(6).Value = table.InnerText
Next
RowCount = 0
For Each table As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes("//*[@id='HomeMyStudents']/tbody/tr['RowCount']/td[8]")
RowCount = RowCount + 1
DGV.Rows(RowCount).Cells(7).Value = table.InnerText
Next
RowCount = 0
For Each table As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes("//*[@id='HomeMyStudents']/tbody/tr['RowCount']/td[9]")
RowCount = RowCount + 1
DGV.Rows(RowCount).Cells(8).Value = table.InnerText
Next
RowCount = 0
For Each table As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes("//*[@id='HomeMyStudents']/tbody/tr['RowCount']/td[10]")
RowCount = RowCount + 1
DGV.Rows(RowCount).Cells(9).Value = table.InnerText
Next
RowCount = 0
For Each table As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes("//*[@id='HomeMyStudents']/tbody/tr['RowCount']/td[11]")
RowCount = RowCount + 1
DGV.Rows(RowCount).Cells(10).Value = table.InnerText
Next
End Sub
Así que, presumiblemente las imágenes se ven algo así como:
<img src="whatever.jpg"/>
en el marcado, ¿verdad?
HAP te permitirá agarrar nodos de imágenes con algo como
... .SelectNodes("./img")
Y por los senderos:
... .Attributes("src").Value()
A partir de ahí, no tengo conocimiento de ninguna característica particular de HAP que le permita realizar ninguna solicitud HTTP como esta, por lo que querrá un WebClient para eso.
Dim wc as new WebClient
wc.DownloadFile(StringContainingThatSrcValue, PathToSaveFileTo)
HTH!