frmScrapeImages.vb
上传用户:szledliu
上传日期:2021-01-29
资源大小:13805k
文件大小:2k
- Imports System.IO
- Public Class frmScrapeImages
- Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
- Me.Close()
- End Sub
- Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
- 'Don't really care if this fails due to some fluke,
- 'Want the process to continue and grab as many images as it can.
- On Error Resume Next
- If txtPath.Text = String.Empty Then
- MessageBox.Show("Please select a folder to save the images to", _
- "Select Folder", MessageBoxButtons.OK, MessageBoxIcon.Information)
- Exit Sub
- End If
- If Not Directory.Exists(txtPath.Text) Then
- MessageBox.Show("Please select a valid directory.", _
- "Select Folder", MessageBoxButtons.OK, MessageBoxIcon.Information)
- Exit Sub
- End If
- btnStart.Enabled = False
- btnCancel.Enabled = False
- Dim oDoc As HtmlDocument = AppManager.CurrentBrowser.Document
- pBar.Visible = True
- pBar.Maximum = oDoc.Images.Count
- Dim oImage As Image
- Dim i As Integer
- For i = 0 To oDoc.Images.Count - 1
- oImage = AppManager.GetWebImage(oDoc.Images(i).GetAttribute("src"))
- If Not IsNothing(oImage) Then
- Dim ofile() As String = Split(oDoc.Images(i).GetAttribute("src"), "/")
- oImage.Save(txtPath.Text & "Image" & i & ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
- lblStatus.Text = "Saving " & ofile(UBound(ofile)).ToString & "..."
- End If
- pBar.Value = i
- Application.DoEvents()
- oImage = Nothing
- Next
- If chkOpen.Checked = True Then
- 'Even though we already checked... we'll check again just to be safe.
- If Directory.Exists(txtPath.Text) Then
- Process.Start(txtPath.Text)
- End If
- End If
- Me.Close()
- End Sub
- Private Sub btnPath_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPath.Click
- Dim fbd As New FolderBrowserDialog
- fbd.ShowDialog()
- txtPath.Text = fbd.SelectedPath
- End Sub
- End Class