[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="<a href="http://images.com/?v=atob3iji.jpg"><img src="http://images.com/thumbs/atob3iji.jpg" border="0"></a>" 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 http://www.vbforums.com/ tags
i wood really appreciate if any one can help me:(
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
Re: Grab Links from Webpage/HTML source
Try, document.getelementsbytagname instead...
Good Luck
Re: Grab Links from Webpage/HTML source
Quote:
Originally Posted by
Spoo
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 http://www.vbforums.com/ but problem was i am not even good at split i did
like this
vb Code:
Text2.Text = WebBrowser1.Document.documentelement.innerhtml
FindText = Split(Text2.Text, "[img]")
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 http://www.vbforums.com/
that should do the trick :(
Check your pm i sent you the site link
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
Re: Grab Links from Webpage/HTML source
vb Code:
Dim X As Long, Y As Long
Dim sHtml As String
sHtml = LCase$(Text1.Text) 'cast to lower case
X = InStr(sHtml, "[img]")
Do While X
X = X + Len("[img]")
Y = InStr(X, sHtml, "[")
If X > 0 And Y > 0 Then
Debug.Print Mid$(sHtml, X, Y - X)
Else
Exit Do
End If
X = InStr(Y, sHtml, "[img]")
Loop
'returns
'http://images.com/thumbs/atob3iji.jpg
'http://images.com/images/atob3iji.jpg
Bon Appétit!
Re: Grab Links from Webpage/HTML source
Quote:
Originally Posted by
Spoo
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:
Text3.Text = Text3.Text & FindText(1)
that shows the result sorry for the noob questions and one more problem is
http://img715.imageshack.us/img715/2534/problemn.png
Should it be like this
vb Code:
b = InStr(UCase, "FindText", tagb)
e = InStr(UCase, "FindText", tage)
once again sorry for the noob questions
Re: Grab Links from Webpage/HTML source
Quote:
Originally Posted by
FireXtol
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 :(
Re: Grab Links from Webpage/HTML source
Quote:
Originally Posted by
_-Rs-_
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.
Re: Grab Links from Webpage/HTML source
Quote:
Originally Posted by
FireXtol
I have modified the post with an example.
guys thanks for all the help snoop and firextol bro
that did the trick :wave: :) :thumb:
Re: Grab Links from Webpage/HTML source
Resil
Let's look at your example HTML code in your OP
- <div id="mostrar_mas_enlaceview">
- <h2 id="mev">Thumbnail + <u>viewer</u> link</h2>
- <div class="ctninput">
- <div class="codex">HTML:</div><div class="inputshare">
- <input tabindex="1" value="<a href="[urlx]http://images.com/?v=atob3iji.jpg"><img[/urxl] src="[urlx]http://images.com/thumbs/atob3iji.jpg"[/urlx] border="0"></a>" onclick="this.focus();this.select();" />
- </div>
- </div>
- <div class="ctninput">
- <div class="codex">BBCode (Forums):</div><div class="inputshare">
- <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();" />
- </div>
- </div>
- </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... :blush:
At least I caught it as I was preparing this rather lengthy post.
Spoo