Solved

Keywords from Internet Explorere Address Bar .....

Posted on 2004-10-30
187 Views
Last Modified: 2010-08-05
Hi all,

I've a small problem. I want to get keywords fro URL e.g:

(http://loginnet.passport.com/login.srf?id=2&svc=mail&cbid=24325&msppjph=1&tw=0&fs=1&fsa=1&fsat=1296000&lc=1033&_lang=EN)

In this URL keywords are:

1. loginnet
2. passport
3. 2 (after (=) value)
4. mail (after (=) value)
5 24325 (after (=) value)
6. 1 (after (=) value)
7. 0 (after (=) value)
8. 1 (after (=) value)
9. 1 (after (=) value)
10. 1296000 (after (=) value)
11. 1033 (after (=) value)
12. EN (after (=) value)

Means kewords split when got (".", "/", "?", "=", "&").

Help me

Waiting for ur positive response.

Thx
0
Question by:bkniazi
    14 Comments
     
    LVL 6

    Expert Comment

    by:Amritpal Singh
    hi bkniazi,

    u can use Instr function for this

    something like

    pos1 = 0
    pos2 = 0

    do while (pos1 <> - 1)
     pos1 = (Instr("./?=&",URL))
     pos2 = (Instr("./?=&),Mid(URL,Pos1))
     keyword = Mid(URL,pos1,pos2-pos1)
    loop

    where URL is the string containing ur URL
       
    0
     
    LVL 6

    Expert Comment

    by:Amritpal Singh
    sorry ,
    do while (pos1 <> - 1)
     pos2 = (Instr("./?=&),Mid(URL,Pos1))
     keyword = Mid(URL,pos1,pos2-pos1)
     pos1 = pos2 + 1
    loop
    0
     
    LVL 14

    Expert Comment

    by:Shiju Sasidharan
    Hi
    plz be specific
    u need to extract all words from that link?
    or only those words which lie between the characters u specified?
    it would be better u specify a small link and give the results u expect to be obtained after extraction
    ;-)
    Shiju
    0
     
    LVL 14

    Expert Comment

    by:Shiju Sasidharan
    hi
    >>specify a small link
    means the url u want to extract

    ;-)
    Shiju
    0
     

    Author Comment

    by:bkniazi
    Dear Shijusn,

    for example: ("http://www.yahoo.com/mess/abc?xyz=123&asd=432")

    i want to extract keywords from it like ('yahoo' and 'mess'  i don't need of 'http://' , don't need of 'www', don't need of '?', don't need of '='and don't need of '&'.
    after '/' i want to get data after (=) sign to (&) sign. Simply between '=' and '&'.

    from this URL keywords are:
    Yahoo
    Mess
    123
    432

    but remember that will be dynimcally.

    thx
    waiting .................................................
    0
     

    Author Comment

    by:bkniazi
    Dear amrit_82,

    try to use ur own code in vb6 plz.

    thx
    0
     
    LVL 14

    Expert Comment

    by:Shiju Sasidharan
    hi bkniazi
    few more questions to make me more clear

    source string will always be url , i.e starting with http://www.  ?
    if it is line http://www.first.second.third.com/?value=234&value2=test
    u need ....

    first
    second
    third
    234
    test
         
    if i am wrong pls correct it.

    u need extracted results in the same order they occur in the url ? or in any order ?
    ;-)
    Shiju



    0
     
    LVL 17

    Expert Comment

    by:zzzzzooc
    Form1:
    ----------------------------
    Option Explicit
    Private Sub Form_Load()
        Dim colQuery As Collection, clsVars As Class1, varTemp As Variant
        'Parse URL for site address
        If ParseAddress("http://loginnet.passport.com/login.srf?id=2&svc=mail&cbid=24325&msppjph=1&tw=0&fs=1&fsa=1&fsat=1296000&lc=1033&_lang=EN", colQuery) = True Then
            For Each varTemp In colQuery
                Debug.Print varTemp
            Next varTemp
        End If
        'Parse URL for variables/values such as "X=1"
        If ParseQuery("http://loginnet.passport.com/login.srf?id=2&svc=mail&cbid=24325&msppjph=1&tw=0&fs=1&fsa=1&fsat=1296000&lc=1033&_lang=EN", colQuery) = True Then
            For Each clsVars In colQuery
                Debug.Print clsVars.var, clsVars.val
            Next clsVars
        End If
    End Sub
    Private Function ParseAddress(ByVal strURL As String, ByRef colQuery As Collection) As Boolean
        Dim strSplit1() As String, intLoop1 As Integer
        Dim strSplit2() As String, intLoop2 As Integer
        Set colQuery = New Collection
        strSplit1() = Split(LCase(strURL), "/")
        For intLoop1 = 0 To UBound(strSplit1)
            If InStr(1, strSplit1(intLoop1), ".") > 0 Then
                strSplit2() = Split(strSplit1(intLoop1), ".")
                For intLoop2 = 0 To UBound(strSplit2)
                    If IsBlacklisted(strSplit2(intLoop2)) = False Then
                        Call colQuery.Add(strSplit2(intLoop2))
                    End If
                Next intLoop2
            Else
                If IsBlacklisted(strSplit1(intLoop1)) = False Then
                    Call colQuery.Add(strSplit1(intLoop1))
                End If
            End If
        Next intLoop1
        ParseAddress = True
    End Function
    Private Function ParseQuery(ByVal strURL As String, ByRef colQuery As Collection) As Boolean
        Dim strSplit1() As String, intLoop1 As Integer
        Dim strSplit2() As String
        Dim clsVars As Class1
        strSplit1() = Split(LCase(strURL), "?")
        'url cannot have more than 1 "?"!!!
        If UBound(strSplit1) = 1 Then
            Set colQuery = New Collection
            strSplit1 = Split(strSplit1(1), "&")
            For intLoop1 = 0 To UBound(strSplit1)
                strSplit2() = Split(strSplit1(intLoop1), "=")
                'var=val cannot have more than one "="!!
                If UBound(strSplit2) = 1 Then
                    Set clsVars = New Class1
                    clsVars.var = strSplit2(0)
                    clsVars.val = strSplit2(1)
                    Call colQuery.Add(clsVars, strSplit2(0))
                End If
            Next intLoop1
            ParseQuery = True
        End If
    End Function
    Private Function IsBlacklisted(ByVal strText As String) As Boolean
        Select Case strText
            Case "www", "http:", "ftp:", ""
                IsBlacklisted = True
        End Select
        If InStr(1, strText, "?") > 0 Then
            IsBlacklisted = True
        End If
    End Function


    Class1:
    -----------------------
    Public var As String
    Public val As String
    0
     
    LVL 14

    Expert Comment

    by:aelatik
    Here you go...

    Private Function ExtractKeywords(URL As String) As String
        Dim KEYWORDS As String
        Dim TMP() As String
        Dim TMP1() As String
            TMP() = Split(URL, "/")
            For Each Item In TMP
                If Item <> "" Then
                    If UCase(Left(Item, 4)) <> "HTTP" Then
                        If InStr(1, Item, ".") > 0 And Item <> TMP(UBound(TMP)) Then
                            TMP1() = Split(Item, ".")
                            Dim I As Long
                            If UBound(TMP1) > 1 Then
                                For I = 1 To UBound(TMP1) - 1
                                    KEYWORDS = KEYWORDS & TMP1(I) & vbCrLf
                                Next
                            End If
                        Else
                            If InStr(1, Item, ".") = 0 Then
                                KEYWORDS = KEYWORDS & Item & vbCrLf
                            End If
                        End If
                    End If
                End If
            Next
           
            If InStr(1, TMP(UBound(TMP)), "?") > 0 Then
                Dim TEMP As String
                    TEMP = Split(TMP(UBound(TMP)), "?")(1)
                    TMP = Split(TEMP, "&")
                    For Each Item In TMP
                        KEYWORDS = KEYWORDS & Split(Item, "=")(1) & vbCrLf
                    Next
            End If
           
            ExtractKeywords = Left(KEYWORDS, Len(KEYWORDS) - 1)
    End Function

    Private Sub Form_Load()
        MsgBox ExtractKeywords("http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/askQuestion.jsp?lc=1033&id=2&tw=2&fs=1&cbid=24325"), vbInformation, "Keywords found"
    End Sub
    0
     
    LVL 14

    Accepted Solution

    by:
    A little modification...

    Private Function ExtractKeywords(URL As String) As String
        Dim KEYWORDS As String
        Dim TMP() As String
        Dim TMP1() As String
            TMP() = Split(URL, "/")
            For Each Item In TMP
                If Item <> "" Then
                    If UCase(Left(Item, 4)) <> "HTTP" Then
                        If InStr(1, Item, ".") > 0 And Item <> TMP(UBound(TMP)) Then
                            TMP1() = Split(Item, ".")
                            If LCase(TMP1(0)) <> "www" Then KEYWORDS = KEYWORDS & TMP1(0) & vbCrLf
                            Dim I As Long
                            If UBound(TMP1) > 1 Then
                                For I = 1 To UBound(TMP1) - 1
                                    KEYWORDS = KEYWORDS & TMP1(I) & vbCrLf
                                Next
                            End If
                        Else
                            If InStr(1, Item, ".") = 0 Then
                                KEYWORDS = KEYWORDS & Item & vbCrLf
                            End If
                        End If
                    End If
                End If
            Next
           
            If InStr(1, TMP(UBound(TMP)), "?") > 0 Then
                Dim TEMP As String
                    TEMP = Split(TMP(UBound(TMP)), "?")(1)
                    TMP = Split(TEMP, "&")
                    For Each Item In TMP
                        KEYWORDS = KEYWORDS & Split(Item, "=")(1) & vbCrLf
                    Next
            End If
           
            ExtractKeywords = Left(KEYWORDS, Len(KEYWORDS) - 1)
    End Function

    Private Sub Form_Load()
        MsgBox ExtractKeywords("http://loginnet.passport.com/login.srf?id=2&svc=mail&cbid=24325&msppjph=1&tw=0&fs=1&fsa=1&fsat=1296000&lc=1033&_lang=EN)"), vbInformation, "Keywords found"
    End Sub
    0
     

    Author Comment

    by:bkniazi
    yes shijusn
    0
     

    Author Comment

    by:bkniazi
    check the Aelatik code.
    0
     
    LVL 1

    Assisted Solution

    by:AsifBangash
    Hi Bkniazi,

    I sugis u to use Aelatik code cause he is a lion of Visual Basic.
    0
     

    Author Comment

    by:bkniazi
    thx Aelatik and u AsifBangash.
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: Foundations of Front-End Development

    Jump-start a lucrative career in front-end web development, with zero previous coding experience required. This course covers the basic programming concepts and languages required for creating engaging websites from scratch.

    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    913 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now