Results 1 to 29 of 29

Thread: [RESOLVED] Need help replacing a url!!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2008
    Posts
    128

    Resolved [RESOLVED] Need help replacing a url!!

    Hey i am making a program that get all the links of the page but now i have a problem, with the links i got i only need a id example: URL: websiteurl.com/userID=1000 <-- than i only need the part 1000
    and all the url's begin with websiteurl.com/userID=*****
    but the ID's variate from 1000 to 100000 the script i use:
    Code:
    Private Sub Command1_Click()
    Dim i As Integer
    Dim s As String
    For i = 0 To browser.Document.links.length - 1
    If InStr(1, browser.Document.links.Item(i).href, "websiteurl.com/userID=") = 1 Then
    s = browser.Document.links.Item(i).href
    script.AddItem s
    End If
    Next i
    End Sub
    
    Private Sub Form_Load()
    Dim i As String
    browser.Navigate Text1.Text
    End Sub
    
    Private Sub script_DblClick()
    browser.Navigate script
    End Sub

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Need help replacing a url!!

    Moved to VB6 And Earlier

  3. #3
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Need help replacing a url!!

    See if this is what you want
    Code:
    Private Sub Command1_Click()
    Dim i As Integer
    Dim s As String
    For i = 0 To browser.Document.links.length - 1
    If InStr(1, browser.Document.links.Item(i).href, "websiteurl.com/userID=") = 1 Then
    s = browser.Document.links.Item(i).href
    script.AddItem s & CStr(1000 + i)  '<-------- IS THIS WHAT YOU MEAN
    End If
    Next i
    End Sub
    
    Private Sub Form_Load()
    Dim i As String
    browser.Navigate Text1.Text
    End Sub
    
    Private Sub script_DblClick()
    browser.Navigate script
    End Sub

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Apr 2008
    Posts
    128

    Re: Need help replacing a url!!

    No i want the ID thats in the url example:
    thesite.com/userID=123123
    thesite.com/userID=123326
    thesite.com/userID=294929
    thesite.com/userID=2949
    Than i want a list with:
    123123
    123326
    294929
    2949

  5. #5
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Need help replacing a url!!

    Then just do a reverse InStr to find the first occurance of a = sign and extract out the ids which will be at the postion of the = sign +1 to the end of the link (I'm assuming that the id number is the very end of the link and nothing else follows it).

    Link = thesite.com/userID=123123 <----123123 is the very last text in the link

    So,

    q = InStrRev(Link, "=")
    If q > 0 Then s = mid(Link, q+1)

  6. #6
    Lively Member
    Join Date
    Apr 2008
    Posts
    74

    Re: Need help replacing a url!!

    Edit. see my post below.
    Last edited by goldenix; Apr 18th, 2008 at 03:20 PM.

    M.V.B. 2008 Express Edition

  7. #7
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Need help replacing a url!!

    The ids will not always be 4 characters

    In his opening post he said

    ...the ID's variate from 1000 to 100000

  8. #8
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Need help replacing a url!!

    Easiest way
    Code:
    MsgBox Split(myURLString, "=")(1)
    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  9. #9
    Lively Member
    Join Date
    Apr 2008
    Posts
    74

    Re: Need help replacing a url!!

    ok ok hire is universal code: we can assume that url may contain multuiple =, so:

    http://www.homeandlearn.co.uk/net/nets7p6.html

    Code:
            Dim URL = "www.thesite.com/userID=123123"
            For i = 1 To URL.Length
    
                MsgBox(URL.Substring(URL.Length - i, i)) ' this is hire to show you what i mean by cuttin goff
    
                'start cutting off 1 char from the end if the URL until we get this: =123123 (>= 0 means if found "=")
                If URL.Substring(URL.Length - i, i).IndexOf("=") >= 0 Then
    
                    'now we have =123123 & we replace = with nothing & vuala
                    MsgBox(URL.Substring(URL.Length - i, i).Replace("=", ""))
    
                    Exit For
                End If
            Next
    Last edited by goldenix; Apr 18th, 2008 at 03:23 PM.

    M.V.B. 2008 Express Edition

  10. #10
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Need help replacing a url!!

    That is definitely the most unneccessary way to do it but if it pleases you then go for it.

  11. #11
    Lively Member
    Join Date
    Apr 2008
    Posts
    74

    Re: Need help replacing a url!!

    Quote Originally Posted by jmsrickland
    That is definitely the most unneccessary way to do it but if it pleases you then go for it.
    You know better way? please feel free to share your idea. I suggested that code, cuz of my limited knowledge..(just started using this language you know & to find a decent vb. guide is really hard, the help file is totally useless you know. )

    Edit: ok i think you can do it also by splitting the URL by "=" & the search Splits for userID= & if found replace userID= with nothing, but i dont think the code will be much shorther.
    Last edited by goldenix; Apr 18th, 2008 at 03:32 PM.

    M.V.B. 2008 Express Edition

  12. #12
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Need help replacing a url!!

    I already showed you in post #5

  13. #13
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: Need help replacing a url!!

    Quote Originally Posted by jmsrickland
    Then just do a reverse InStr to find the first occurance of a = sign and extract out the ids which will be at the postion of the = sign +1 to the end of the link (I'm assuming that the id number is the very end of the link and nothing else follows it).

    Link = thesite.com/userID=123123 <----123123 is the very last text in the link

    So,

    q = InStrRev(Link, "=")
    If q > 0 Then s = mid(Link, q+1)
    +1

    Why make it more complicated than it needs to be...if there were other parameters in the URL then maybe it would need some modifications but for the OP's question I don't see any need for complicating it or even using the split function.

    Just my opinion though.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Apr 2008
    Posts
    128

    Re: Need help replacing a url!!

    I still didn't find a solution
    I only get wrong answers
    I Need a ID grabber that grabs all the id's from a website and the url is always
    thesite.com/userid=conf=123333 ( there are 2 times a "=" sing ) and with the solutions i got i didn't find a solution only cutting of a already existing url but the id is always different!
    so it isn't always thesite.com/userid=conf=123333 it also can be
    thesite.com/userid=conf=999999
    thesite.com/userid=conf=99999
    thesite.com/userid=conf=9999
    thesite.com/userid=conf=72481
    thesite.com/userid=conf=36789
    thesite.com/userid=conf=1596
    thesite.com/userid=conf=12374
    thesite.com/userid=conf=756916
    thesite.com/userid=conf=89456
    thesite.com/userid=conf=33274
    thesite.com/userid=conf=123333
    thesite.com/userid=conf=9561
    thesite.com/userid=conf=32749
    thesite.com/userid=conf=216872
    thesite.com/userid=conf=984651
    AND tons of more id's

  15. #15
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Need help replacing a url!!

    What is about what I showed you that doesn't work?

    You tell us that in all cases the URL will end with a number that can range from 1000 to 10000, right?

    And you tell us that in all cases the URL wil end in the following way:

    ...........=nnnnnn, right?

    It doesn't matter what the rest of the URL looks like as long as it ends with an equal sign and a number from 1000 to 10000 the method I showed you works.

    q = InStrRev("thesite.com/userid=conf=123333", "=")

    The above will set the variable q to the value 24 which is the position of the = sign to the left on the number 123333.

    Now, if q is greater than 0 it must be the value 24, agreed?

    So.....

    s = Mid("thesite.com/userid=conf=123333", q + 1)

    if q is 24 then q +1 is 25 which is the position of the number 1 in the value 123333, agreed?

    The above will get the middle part of the string at position 25 which is the entire number 123333 and put it in the variable s.

    Now if you think that doesn't work then I don't know what you want but it works exactly the way I am telling you it works and I believe I am interepting your request correctly. If I am not then tell me so.

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Apr 2008
    Posts
    128

    Re: Need help replacing a url!!

    Now it only adds 123333 -.-

  17. #17
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Need help replacing a url!!

    It doesn't add anything.

    Answer me this: am I interpeting your request correctly?

    Answer me this: Does it not put the number 123333 in the variable s?

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Apr 2008
    Posts
    128

    Re: Need help replacing a url!!

    Yea i had put a wrong letter ( my fault )
    it doesnt add anything :S
    [edit]
    Code:
    i now have the script:
    Private Sub Command1_Click()
    Dim i As Integer
    Dim s As String
    For i = 0 To browser.Document.links.length - 1
    If InStr(1, browser.Document.links.Item(i).href, "WEBSITEUR.COM/ID=") = 1 Then
    s = browser.Document.links.Item(i).href
    q = InStrRev("WEBSITEURL.COM/ID=", "=")
    s = Mid("WEBSITEURL.COM/ID=", q + 1)
    script.AddItem s
    End If
    Next i
    End Sub
    
    Private Sub Form_Load()
    Dim i As String
    browser.Navigate Text1.Text
    End Sub
    
    Private Sub script_DblClick()
    browser.Navigate script
    End Sub
    Last edited by menzow; Apr 19th, 2008 at 02:41 PM.

  19. #19
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Need help replacing a url!!

    Quote Originally Posted by menzow
    Now it only adds 123333 -.-
    I believe jmsrickland's is just showing you a hard coded sample,

    I haven't tested this but it might look something like this,
    Code:
    If InStr(1, browser.Document.links.Item(i).href, "websiteurl.com/userID=") = 1 Then
    s = browser.Document.links.Item(i).href
    q = InStrRev(s, "=")
    script.AddItem Mid$(s, q + 1)
    End If

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Apr 2008
    Posts
    128

    Re: Need help replacing a url!!

    thanks Edgemeal!!!!
    its working!! thank you soooo much

  21. #21
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Need help replacing a url!!

    Edgemeal, that is exactly what I showed him in post #5, he just didn't pay any attention to it.

  22. #22
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: Need help replacing a url!!

    Quote Originally Posted by menzow
    thanks Edgemeal!!!!
    its working!! thank you soooo much
    Well, thank you too! I guess I didn't help you, right?

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    Apr 2008
    Posts
    128

    Re: Need help replacing a url!!

    Quote Originally Posted by jmsrickland
    Edgemeal, that is exactly what I showed him in post #5, he just didn't pay any attention to it.
    That didn't work -.-"

  24. #24

    Thread Starter
    Addicted Member
    Join Date
    Apr 2008
    Posts
    128

    Re: [RESOLVED] Need help replacing a url!!

    And now i have a new problem

    it shows duplicated ID's ( 2 times )
    becouse there is a
    thewebsite.com/id=12312
    and
    thewebsite.com/id=conf=12312

  25. #25
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: Need help replacing a url!!

    Quote Originally Posted by jmsrickland
    Edgemeal, that is exactly what I showed him in post #5, he just didn't pay any attention to it.
    Ya I see it now.

  26. #26
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] Need help replacing a url!!

    And now he complains that post #5 doesn't work.

    Geezz, some people you just can't get it accross to.

  27. #27
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: [RESOLVED] Need help replacing a url!!

    Quote Originally Posted by menzow
    And now i have a new problem

    it shows duplicated ID's ( 2 times )
    becouse there is a
    thewebsite.com/id=12312
    and
    thewebsite.com/id=conf=12312
    I assume you don't want duplicates in the listbox, if so add this,

    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, _
     ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Private Const LB_FINDSTRINGEXACT = &H1A2
    
    Private Function FindItem(Lst As ListBox, strText As String) As Integer
        FindItem = SendMessage(Lst.hWnd, LB_FINDSTRINGEXACT, -1, ByVal strText)
    End Function
    and replace -> script.AddItem Mid$(s, q + 1) <- with,
    Code:
    If FindItem(script, Mid$(s, q + 1)) = -1 Then script.AddItem Mid$(s, q + 1)

  28. #28

    Thread Starter
    Addicted Member
    Join Date
    Apr 2008
    Posts
    128

    Re: [RESOLVED] Need help replacing a url!!

    Huh i get the error with :
    Compile error:
    Only comments can appear after End sub,End property or End function

    Code:
    Private Sub Form_Load()
    Dim i As String
    browser.Navigate Text1.Text
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, _
     ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Private Const LB_FINDSTRINGEXACT = &H1A2
    
    Private Function FindItem(Lst As ListBox, strText As String) As Integer
        FindItem = SendMessage(Lst.hWnd, LB_FINDSTRINGEXACT, -1, ByVal strText)
    End Function
    End Sub
    No matter where i put this i get that error :S

  29. #29
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: [RESOLVED] Need help replacing a url!!

    You have a function within a sub

    Do it this way...

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

    Private Const LB_FINDSTRINGEXACT = &H1A2

    Private Sub Form_Load()
    Dim i As String
    browser.Navigate Text1.Text

    End Sub
    Private Function FindItem(Lst As ListBox, strText As String) As Integer
    FindItem = SendMessage(Lst.hWnd, LB_FINDSTRINGEXACT, -1, ByVal strText)
    End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width