Hoffe, dass jemand helfen kann, wie ich es schon lange versucht habe, herauszufinden. Ich verwende das Agility-Paket, um Daten aus einer Tabelle zu extrahieren und in ein Datenraster zu stellen (das Datenraster ist nicht wichtig. Ich benutze es nur, um zu sehen, ob die Extraktion funktioniert). Wie auch immer, in der ersten Spalte der Tabelle sind Miniaturbilder enthalten. Ich kann den ganzen Text mit dem folgenden Code extrahieren, aber ich weiß nicht, wie man die Bilder aus der ersten Spalte extrahiert ... Kann jemand helfen?
PS Ich habe die Webseite als eine MHL-Datei gespeichert, da sie keine Daten direkt daraus extrahieren konnte - ich glaube, dass es etwas mit den Sicherheit / Anmeldeinformationen der Site zu tun hat. Ich weiß nicht, ob ich mir die Dinge leichter oder schwerer gemacht habe.
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
Also, die Bilder sehen vermutlich so aus:
<img src="whatever.jpg"/>
im Markup, oder?
HAP ermöglicht es Ihnen, Bildknoten mit etwas wie zu greifen
... .SelectNodes("./img")
Und für die Wege:
... .Attributes("src").Value()
Von da an sind mir keine speziellen HAP-Funktionen bekannt, mit denen Sie tatsächlich HTTP-Anforderungen wie diese ausführen können. Daher benötigen Sie einen WebClient .
Dim wc as new WebClient
wc.DownloadFile(StringContainingThatSrcValue, PathToSaveFileTo)
HTH!