Page 1 of 1

Get specefic items from tags on website

Posted: Tue Jul 23, 2013 4:19 pm
by AnoPem
Im trying to create a tool where you just click a button and it will get you the info needed and add it to a listview

From this link: http://www.internet-radio.com/stations/hardcore/page1

Eg when the website loads it will get the name from the radio station and the wmp link and add it to a listview

Name
Dance Uk Stream Danceradiouk.Com
The link the button with the wmp logo goes to
http://servers.internet-radio.com/tools ... pls&t=.m3u
Image

Anyone have a clue on how i could accomplish this ?

Re: Get specefic items from tags on website

Posted: Tue Jul 23, 2013 4:25 pm
by visualtech
use RegEx :)

Re: Get specefic items from tags on website

Posted: Tue Jul 23, 2013 5:25 pm
by AnoPem
visualtech wrote:
use RegEx :)
Can you give me an example ?

Re: Get specefic items from tags on website

Posted: Wed Jul 24, 2013 12:40 am
by mandai
It is unlikely that regex by itself will give the needed functionality.

You can use a WebBrowser control to access the HTML elements.

This sample will list the link names/wmp links from the table on that page:
Code: Select all
    Private Sub btnTest_Click(sender As System.Object, e As System.EventArgs) Handles btnTest.Click

        WebBrowser1.ScriptErrorsSuppressed = True
        WebBrowser1.Navigate("http://www.internet-radio.com/stations/hardcore/page1")

    End Sub

    Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

        If e.Url.ToString() = "http://www.internet-radio.com/stations/hardcore/page1" Then

            Dim tables As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("table")

            Dim rows As HtmlElementCollection = tables(0).GetElementsByTagName("tr")

            For i As Integer = 0 To rows.Count - 1

                Dim cells As HtmlElementCollection = rows(i).GetElementsByTagName("td")

                Dim links As HtmlElementCollection = cells(0).GetElementsByTagName("a")
                Dim href As String = links(1).GetAttribute("href")

                Dim links2 As HtmlElementCollection = cells(1).GetElementsByTagName("a")
                Dim title As String = links2(0).InnerText

                ListView1.Items.Add(New ListViewItem(New String() {title, href}))

            Next
        End If
    End Sub

Re: Get specefic items from tags on website

Posted: Wed Jul 24, 2013 4:50 pm
by AnoPem
mandai wrote:
It is unlikely that regex by itself will give the needed functionality.

You can use a WebBrowser control to access the HTML elements.

This sample will list the link names/wmp links from the table on that page:
Code: Select all
    Private Sub btnTest_Click(sender As System.Object, e As System.EventArgs) Handles btnTest.Click

        WebBrowser1.ScriptErrorsSuppressed = True
        WebBrowser1.Navigate("http://www.internet-radio.com/stations/hardcore/page1")

    End Sub

    Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

        If e.Url.ToString() = "http://www.internet-radio.com/stations/hardcore/page1" Then

            Dim tables As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("table")

            Dim rows As HtmlElementCollection = tables(0).GetElementsByTagName("tr")

            For i As Integer = 0 To rows.Count - 1

                Dim cells As HtmlElementCollection = rows(i).GetElementsByTagName("td")

                Dim links As HtmlElementCollection = cells(0).GetElementsByTagName("a")
                Dim href As String = links(1).GetAttribute("href")

                Dim links2 As HtmlElementCollection = cells(1).GetElementsByTagName("a")
                Dim title As String = links2(0).InnerText

                ListView1.Items.Add(New ListViewItem(New String() {title, href}))

            Next
        End If
    End Sub
Thanks this was excatly what i needed