Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello, guy. I want your help to check this code below, I try to create a program which can help me to extract the URL in any website which has URL begin with "https://edge" and end of URL must to "playlist.m3u8". but the code i do is not working, i try to find solution many website but no one can do it. please share me if you know how to do it.

What I have tried:

Imports System.IO
Imports System.Net
Imports System.Text.RegularExpressions

Public Class Form1
    Private requestweb As HttpWebRequest
    Private responseWeb As HttpWebResponse
    Private Sub btnFind_Click(sender As Object, e As EventArgs) Handles btnFind.Click
        Dim WebSource As String
        Dim objStreamReader As StreamReader = Nothing

        requestweb = CType(WebRequest.Create(txtURL.Text), HttpWebRequest)
        With requestweb
            .UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0b; Windows NT 5.1)"
            .Method = "GET"
            .Timeout = 10000
        End With

        Try
            responseWeb = CType(requestweb.GetResponse(), HttpWebResponse)
        Catch ex As Exception
            MessageBox.Show("Error retrieving the Web page " &
                "you requested. Please check the entered Url and your internet connection")
            Exit Sub
        End Try

        If Not IsNothing(responseWeb.GetResponseStream()) Then
            Try
                objStreamReader = New StreamReader(responseWeb.GetResponseStream())
                WebSource = objStreamReader.ReadToEnd
            Catch ex As Exception
                MessageBox.Show(ex.Message)
                Exit Sub
            Finally
                responseWeb.Close()
                objStreamReader.Close()
            End Try

        End If
        lsvlinks.Items.Clear()
        Dim strReg As String


'here is code which not working 

        strReg = "<a\s+href\s*=\s*""https://edge""?>(.+)</a>"

'-----------------------------
        Dim reg As New Regex(strReg, RegexOptions.IgnoreCase)
#Disable Warning BC42104 ' Variable is used before it has been assigned a value
        Dim m As Match = reg.Match(input:=WebSource)
#Enable Warning BC42104 ' Variable is used before it has been assigned a value
        While m.Success
            Dim lvi As New ListViewItem()
            lvi.Text = m.Groups(1).Value
            lsvlinks.Items.Add(lvi)
            m = m.NextMatch()
        End While
    End Sub
Posted
Updated 17-Jan-22 5:44am
v2
Comments
Richard MacCutchan 14-Jan-22 10:59am    
" but the code i do is not working"
Unfortunately that does not mean anything to anyone here. Please use the Improve question link above, and add complete details of what is not working.
lov kiemtheng 14-Jan-22 11:04am    
i really wish someone who expert or have more knowledge about how to grab the URL like topic below , please help me
CHill60 14-Jan-22 11:16am    
There probably is, but you need to add complete details of what is not working - as Richard has already told you. Also, why have you tagged your question "VB6" - this is not VB6 code
lov kiemtheng 14-Jan-22 11:36am    
hi chill60, i create this program in vb.net , i try to grab the URL from any website which content https://edge

i try to use this :

strReg = "<a\s+href\s*=\s*""https: edge""?="">(.+)"

but not working to grab the URL
Richard Deeming 14-Jan-22 11:41am    
You really need to work on your listening skills!

Constantly repeating "it's not working" tells us precisely nothing.

If you can't explain clearly and precisely what the problem is, then nobody can help you.

1 solution

Your regex seems over-complicated and doesn't check for playlist.m3u8 at all. Why not keep it simple with
^https://edge.*playlist.m3u8$
- ^https://edge line must start with "https://edge"
- .* followed by zero or more characters
- playlist.m3u8$ string ends with "playlist.m3u8"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900