PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197

PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[RESOLVED] Grab Links from Webpage-VBForums
Results 1 to 11 of 11

Thread: [RESOLVED] Grab Links from Webpage

  1. #1

    Thread Starter
    Lively Member _-Rs-_'s Avatar
    Join Date
    Aug 2009
    Posts
    84

    Resolved [RESOLVED] Grab Links from Webpage

    Any can one take a look at this html source and tell me how i can grab the links out of it "i use Document.getElementById to grab links or data but in this one when i grab using the ID it dosent grab the links other then it grabs some text please take a look"

    HTML Code:
    <div id="mostrar_mas_enlaceview">
                <h2 id="mec">Thumbnail</u> link</h2>
                <div class="ctninput">
                    <div class="codex">HTML:</div><div class="inputshare">
                    <input tabindex="1" value="&lt;a href=&quot;http://images.com/?v=atob3iji.jpg&quot;&gt;&lt;img src=&quot;http://images.com/thumbs/atob3iji.jpg&quot; border=&quot;0&quot;&gt;&lt;/a&gt;" onclick="this.focus();this.select();" />
                    </div>
                </div>
                <div class="ctninput">
                    <div class="codex">BBCode :</div><div class="inputshare">
                    <input tabindex="2" value="[url=http://images.com/?v=atob3iji.jpg][img]http://images.com/thumbs/atob3iji.jpg[/img][/url]" onclick="this.focus();this.select();" />
                    </div>
                </div>
            </div>
            
            <div id="mostrar_directa">
                <h2 id="mc">Show directly this image</h2>
                <div class="ctninput">
                    <div class="codex"><a href="http://images.com/?v=atob3iji.jpg" target="_blank">Viewer:</a></div>
                    <div class="inputshare"><input tabindex="3" value="http://images.com/?v=atob3iji.jpg" onclick="this.focus();this.select();" /></div>
                </div>
                <div class="ctninput">
                    <div class="codex">BBCode (Forums):</div>
                    <div class="inputshare"><input tabindex="4" value="[img]http://images.com/images/atob3iji.jpg[/img]" onclick="this.focus();this.select();" /></div>
                </div>
                <div class="ctninput">
                    <div class="codex"><a href="http://images.com/images/atob3iji.jpg" target="_blank">URL:</a></div>
                    <div class="inputshare"><input tabindex="5"value="http://images.com/images/atob3iji.jpg" onclick="this.focus();this.select();" /></div>
                </div>
                        </div>
            
    		<div id="mostrar_social">
    I am still a leaner so i dont know much and one more thing can any one tell me how can i extract a text or link between the [IMG] and [/IMG] tags
    i wood really appreciate if any one can help me
    Last edited by _-Rs-_; Jun 6th, 2010 at 05:54 PM.


  2. #2
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Grab Links from Webpage/HTML source

    RS

    Try the InStr function.

    What VB code do you have so far that "grabs" the text?
    Where is the "grabbed text" put .... into an array? into something else?

    Spoo

  3. #3
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: Grab Links from Webpage/HTML source

    Try, document.getelementsbytagname instead...



    Good Luck
    Option Explicit should not be an Option!

  4. #4

    Thread Starter
    Lively Member _-Rs-_'s Avatar
    Join Date
    Aug 2009
    Posts
    84

    Re: Grab Links from Webpage/HTML source

    Quote Originally Posted by Spoo View Post
    RS

    Try the InStr function.

    What VB code do you have so far that "grabs" the text?
    Where is the "grabbed text" put .... into an array? into something else?

    Spoo
    Bro first using the webbroswer i navigate to the website and then using same

    ById().Click it clicks the browse button and it uploadeds the image after it's

    uploaded all i want is to get the image link i even tried the bytagname but i

    am still a noob so i may have not done it right so it didnt work then i tried to

    grab the html and using Findtext and split() i wanted to grab the link from

    between [IMG] and [/IMG] but problem was i am not even good at split i did

    like this


    vb Code:
    1. Text2.Text = WebBrowser1.Document.documentelement.innerhtml
    2. FindText = Split(Text2.Text, "[img]")
    3. Text3.Text = Text3.Text & FindText(1)

    but that code only split till [img] after that comes the image link but after

    the image link there's still useless html codes

    if you can give me example on how to grab link between [IMG] and [/IMG]

    that should do the trick

    Check your pm i sent you the site link
    Last edited by _-Rs-_; Jun 5th, 2010 at 12:05 PM.


  5. #5
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Grab Links from Webpage/HTML source

    RS

    Maybe something like this:

    Code:
    Text2.Text = WebBrowser1.Document.documentelement.innerhtml
    FindText = Split(Text2.Text, vbCrLf)  ' uses vbCrLf instead of what you had
    nn = UBound(FindText)                 ' num elements in array FindText
    tagb = "<IMG"                         ' begin tag
    tage = "</IMG"                        ' end tag
    For ii = 0 to nn
        b = InStr(UCase(FindText, tagb)   ' beginning pos of tagb
        e = InStr(UCase(FindText, tage)   ' beginning pos of tage
        If b > 0 Then                     ' only interested if have tagb in this given string
            < code parse based on b and e >
        End If
    Next ii
    Does this get you started?
    FWIW, I noticed that tags seem to use "<" instead of "[".

    EDIT:
    As you may have guessed, I'm not too familiar with html codes.
    Looks like I was wrong:

    Replace: tagb = "<IMG"
    .... with: tagb = "[IMG"

    ... and ditto with tage

    Spoo
    Last edited by Spoo; Jun 5th, 2010 at 11:19 AM.

  6. #6
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Grab Links from Webpage/HTML source

    vb Code:
    1. Dim X As Long, Y As Long
    2. Dim sHtml As String
    3. sHtml = LCase$(Text1.Text) 'cast to lower case
    4.  
    5. X = InStr(sHtml, "[img]")
    6. Do While X
    7.   X = X + Len("[img]")
    8.   Y = InStr(X, sHtml, "[")
    9.   If X > 0 And Y > 0 Then
    10.     Debug.Print Mid$(sHtml, X, Y - X)
    11.   Else
    12.     Exit Do
    13.   End If
    14.   X = InStr(Y, sHtml, "[img]")
    15. Loop
    16.  
    17. 'returns
    18. 'http://images.com/thumbs/atob3iji.jpg
    19. 'http://images.com/images/atob3iji.jpg

    Bon App&#233;tit!

  7. #7

    Thread Starter
    Lively Member _-Rs-_'s Avatar
    Join Date
    Aug 2009
    Posts
    84

    Re: Grab Links from Webpage/HTML source

    Quote Originally Posted by Spoo View Post
    RS

    Maybe something like this:

    Code:
    Text2.Text = WebBrowser1.Document.documentelement.innerhtml
    FindText = Split(Text2.Text, vbCrLf)  ' uses vbCrLf instead of what you had
    nn = UBound(FindText)                 ' num elements in array FindText
    tagb = "<IMG"                         ' begin tag
    tage = "</IMG"                        ' end tag
    For ii = 0 to nn
        b = InStr(UCase(FindText, tagb)   ' beginning pos of tagb
        e = InStr(UCase(FindText, tage)   ' beginning pos of tage
        If b > 0 Then                     ' only interested if have tagb in this given string
            < code parse based on b and e >
        End If
    Next ii
    Does this get you started?
    FWIW, I noticed that tags seem to use "<" instead of "[".

    EDIT:
    As you may have guessed, I'm not too familiar with html codes.
    Looks like I was wrong:

    Replace: tagb = "<IMG"
    .... with: tagb = "[IMG"

    ... and ditto with tage

    Spoo
    Bro i added the code you gave but as you i am noob how do i show the

    result in text box as u seen in my code in the end i added

    vb Code:
    1. Text3.Text = Text3.Text & FindText(1)

    that shows the result sorry for the noob questions and one more problem is



    Should it be like this
    vb Code:
    1. b = InStr(UCase, "FindText", tagb)
    2. e = InStr(UCase, "FindText", tage)

    once again sorry for the noob questions


  8. #8

    Thread Starter
    Lively Member _-Rs-_'s Avatar
    Join Date
    Aug 2009
    Posts
    84

    Re: Grab Links from Webpage/HTML source

    Quote Originally Posted by FireXtol View Post
    I'm not sure why you'd use split....

    Basically, what I suggest is(as far as built-in string procedures):
    • x = Instr(strHtml, "[IMG]") 'get the char location of "[IMG]"(optionally use Y as the start)
    • Ensure: x > 0
    • Add the len("[IMG]") to x
    • let x = that result of addition
    • make y = Instr(x, strHtml, "[") 'find the closing brace, using X as the start
    • Ensure: y > 0
    • Use: strUrl = Mid$(strHtml, x, y - x - 1) to get the URL
    • this process can be repeated specifying Y as the new start location for Instr
    bro i am new leaner i have no idea what you said if you can give me a

    example i wood appreciate it
    Last edited by _-Rs-_; Jun 23rd, 2010 at 08:55 AM.


  9. #9
    Fanatic Member FireXtol's Avatar
    Join Date
    Apr 2010
    Posts
    874

    Re: Grab Links from Webpage/HTML source

    Quote Originally Posted by _-Rs-_ View Post
    bro i am noob new leaner i have no idea what you said if you can give me a

    example i wood appreciate it
    I have modified the post with an example.

  10. #10

    Thread Starter
    Lively Member _-Rs-_'s Avatar
    Join Date
    Aug 2009
    Posts
    84

    Re: Grab Links from Webpage/HTML source

    Quote Originally Posted by FireXtol View Post
    I have modified the post with an example.
    guys thanks for all the help snoop and firextol bro

    that did the trick


  11. #11
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Grab Links from Webpage/HTML source

    Resil

    Let's look at your example HTML code in your OP

    1. <div id="mostrar_mas_enlaceview">
    2. <h2 id="mev">Thumbnail + <u>viewer</u> link</h2>
    3. <div class="ctninput">
    4. <div class="codex">HTML:</div><div class="inputshare">
    5. <input tabindex="1" value="&lt;a href=&quot;[urlx]http://images.com/?v=atob3iji.jpg&quot;&gt;&lt;img[/urxl] src=&quot;[urlx]http://images.com/thumbs/atob3iji.jpg&quot;[/urlx] border=&quot;0&quot;&gt;&lt;/a&gt;" onclick="this.focus();this.select();" />
    6. </div>
    7. </div>
    8. <div class="ctninput">
    9. <div class="codex">BBCode (Forums):</div><div class="inputshare">
    10. <input tabindex="2" value="[url=http://images.com/?v=atob3iji.jpg][imgx]http://images.com/thumbs/atob3iji.jpg[/imgx][/urlx]" onclick="this.focus();this.select();" />
    11. </div>
    12. </div>
    13. </div>


    In the above, I have taken the first 13 lines of your example.

    I purposely changed [img] to [imgx] and [/img] to [/imgx] so the text would display .. thus ignore, is just for demo purposes

    So, if I understand your current question properly, you want to know how to extract http://images.com/thumbs/atob3iji.jpg from
    array element 10.

    Maybe something like this:
    Code:
    Text2.Text = WebBrowser1.Document.documentelement.innerhtml
    FindText = Split(Text2.Text, vbCrLf)  ' uses vbCrLf instead of what you had
    nn = UBound(FindText)                 ' num elements in array FindText
    tagb = "[IMG]"                        ' begin tag
    tage = "[/IMG]" 
    Dim txtURL(100) as String
    Dim begURL as Long
    Dim lenURL as Long
    Dim lenTAGb as Long
    uu = 0
    lenTAGb = 5                           ' ie, length of [IMG]
    For ii = 0 to nn
        b = InStr(UCase(FindText(ii), tagb)   ' = 70, or thereabouts
        e = InStr(UCase(FindText(ii), tage)   ' = 95, or thereabouts
        If b > 0 Then                         ' only interested if have tagb in this given string
            uu = uu + 1
            begURL = b + lenTAGb
            lenURL = e - b - lenTAGb
            txtURL(uu) = Mid(FindText(ii), begURL, lenURL)
        End If
    Next ii
    New statements shown in blue
    Corrections to statements in my prior post shown in red

    In our example case, you would get the following result:

    txtURL(1) = "http://images.com/thumbs/atob3iji.jpg"

    • I initialized uu (the "use" counter) at 100 -- this may be overkill.
    • I think this is what you were asking about >> ie, the parsing bit
    • If I'm wrong, let me know.


    EDIT:
    It took me so long to compose this post .. looks like you already
    have resolved the issue.... oh well ...

    EDIT-2:
    Yes, sorry about that compile error you got. How silly of me...
    At least I caught it as I was preparing this rather lengthy post.

    Spoo
    Last edited by Spoo; Jun 5th, 2010 at 01:39 PM. Reason: saw subsequent posts

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width