0

我正在开发一个网络爬虫,这导致我将网页保存为 mht 文件以进行操作(由于权限和我的编程技能,无法访问页面并在线提取)。

我正在使用敏捷包将文本从表格中剥离出来,效果很好,但是页面上的表格也包含许多图像。

我已经尝试了很多不同的方法,但就是无法从这个文件中提取图像..有人可以帮忙吗?

非常感谢

Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click


    Dim Web As New HtmlAgilityPack.HtmlWeb
    Dim Doc As New HtmlAgilityPack.HtmlDocument
    Dim RowCount As Integer = 1




    Doc.Load("J:\table1.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 hNodeCol As HtmlNodeCollection = Doc.DocumentNode.SelectNodes("//a[@href]")
    Dim rows As HtmlAgilityPack.HtmlNodeCollection = tables(0).SelectNodes("//*[@id=HomeMyStudents]")

    For Each Link As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes("//*[@id='HomeMyStudents']/tbody/tr['RowCount']/td[1]")
        RowCount = RowCount + 1
        '  DGV.Rows(RowCount).Cells(0).Value = Link.InnerText
        DGV.Rows.Add("test", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
        '  DGV.Rows.Add("test")
    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 = table.InnerText

    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
    RowCount = 0
    For Each Link As HtmlAgilityPack.HtmlNode In Doc.DocumentNode.SelectNodes("//*[@id='HomeMyStudents']/tbody/tr['RowCount']/td[1]")
        'RowCount = RowCount + 1
        'DGV.Rows(RowCount).Cells(11).Value = Link.InnerText
        '  DGV.Rows.Add("test", Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
        '  DGV.Rows.Add("test")
        ListBox1.Items.Add(Link.InnerText)
    Next


End Sub
4

0 回答 0