VB NET dramacool download web crawler


Imports System.ComponentModel
Imports System.Net
Imports System.Text.RegularExpressions

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("https://www4.dramacool9.io/meteor-garden-2018-episode-27.html")

        Dim response As System.Net.HttpWebResponse = request.GetResponse
        Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream)
        Dim rssourceCode As String = sr.ReadToEnd

        Dim r As New Regex("<h3 class=""title"" onclick=""window.location = '([^<]*)'"">([^<]*)</h3>")
        Dim matches As MatchCollection = r.Matches(rssourceCode)

        For Each itemcode As Match In matches
            ListBox1.Items.Add(itemcode.Groups(1).ToString)

        Next
    End Sub

    Private Sub ListBox1_DoubleClick(sender As Object, e As EventArgs) Handles ListBox1.DoubleClick
        MessageBox.Show(ListBox1.SelectedItem.ToString)
        Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("https://www4.dramacool9.io" + ListBox1.SelectedItem.ToString)

        Dim response As System.Net.HttpWebResponse = request.GetResponse
        Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream)
        Dim rssourceCode As String = sr.ReadToEnd

        Dim r As New Regex("<iframe allowfullscreen=""true"" webkitallowfullscreen=""true"" mozallowfullscreen=""true"" marginheight=""0"" marginwidth=""0"" scrolling=""no"" frameborder=""0"" style=""width: 100%"" src=""([^<]*)"" target=""_blank""></iframe>")
        Dim matches As Match = r.Match(rssourceCode)

        Dim downloadRequest As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("https:" & matches.Groups(1).ToString())
        Dim downloadresponse As System.Net.HttpWebResponse = downloadRequest.GetResponse
        Dim dsr As System.IO.StreamReader = New System.IO.StreamReader(downloadresponse.GetResponseStream)
        Dim downloadrssourceCode As String = dsr.ReadToEnd
        Dim downloadRegex As New Regex("file: '([^<]*)',label: 'auto P','type' : 'mp4'")
        Dim downloadMatches As Match = downloadRegex.Match(downloadrssourceCode)
        Dim client As WebClient = New WebClient
        AddHandler client.DownloadProgressChanged, AddressOf client_ProgressChanged
        AddHandler client.DownloadFileCompleted, AddressOf client_DownloadCompleted
        client.DownloadFileAsync(New Uri(downloadMatches.Groups(1).ToString()), "E:\meteor garden" & ListBox1.SelectedItem.ToString)
    End Sub

    Private Sub client_DownloadCompleted(sender As Object, e As AsyncCompletedEventArgs)
        MessageBox.Show("Download Complete")
    End Sub

    Private Sub client_ProgressChanged(sender As Object, e As DownloadProgressChangedEventArgs)
        Dim bytesIn As Double = Double.Parse(e.BytesReceived.ToString())
        Dim totalBytes As Double = Double.Parse(e.TotalBytesToReceive.ToString())
        Dim percentage As Double = bytesIn / totalBytes * 100
        Label1.Text = percentage
        ProgressBar1.Value = Int32.Parse(Math.Truncate(percentage).ToString())
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBox1.SelectedIndexChanged

    End Sub
End Class

No comments:

The Win Machine

The Road to Hell is Paved with Intervention ͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏     ­͏    ...

Contact Form

Name

Email *

Message *