Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get info from a Hypertext link innertext 1

Status
Not open for further replies.

samphdauto

Technical User
Nov 27, 2002
11
GB
I have been really spending time on this for no avail. Please point me to the right direction

I have a URL for example which if displayed on a browser it has titles of stories. For example a hypertext link story (The car of the
future)

How can I retrieve the text of the story (The car of the future) to variable MyStory? Given that I already know the main URL address and the story title on that page?


Thank a lot

Sam
 

Once the web page is loaded in the WB you can call this code in a module or something like it...
[tt]
Option Explicit
Public Type LinkInfo
LinkText As New Collection
LinkHref As New Collection
End Type

Public Function GetLinkInfo(WB As WebBrowser) As LinkInfo

Dim L

For Each L In WB.Document.Links
GetLinkInfo.LinkHref.Add L.Href
GetLinkInfo.LinkText.Add L.innertext
Next

End Function
[/tt]

This will return all of the links in the page with the url of the link and the text (if any). You would call this function with something like...
[tt]
Dim MyInfo As LinkInfo

MyInfo = GetLinkInfo(WebBrowser1)
[/tt]

Now, this is not really what you are looking for but you could then run through the UDT Collections testing the innertext/LinkText against the string you are wanting to find.

Good Luck
 
thanks alot..
what would the change in the code be if I don't use a WebBrowser. I want the info in variants so I can save them in my Access DB.


Sam
 

To answer your first question, you previously said "on a browser", of which I gave you code for by using the webbrowser control. Now you are asking without a webbrowser control which is an entirly different question. So I will ask you a question in return. What technology do you want to use? Inet control? XML object? Other? Pretty much all of the other technologies will require you to at least have a string variable to recieve a text stream or you could save the resulting file to disk. If you want to use these other technologies you could then do exactly what you want by parsing out the resulting string.

For your second question/statement you can treat a collection as an object and like a variant because it is an object that is not defined unless defined by the object it describes.

I Hope this helps, GOOD LUCK
 
I will be using Inet.
would this work?

Option Explicit
Public Type LinkInfo
LinkText As New Collection
LinkHref As New Collection
End Type

Public Function GetLinkInfo(Internet As Inet) As LinkInfo
'This will return all of the links in the page with
'the url of the link and the text (if any).
'then run through the UDT Collections testing the
'innertext/LinkText against the string you are wanting to find.

Dim L

For Each L In Internet.Document.Links
GetLinkInfo.LinkHref.Add L.Href
GetLinkInfo.LinkText.Add L.innertext
Next

End Function

and then run this

Private Sub cmdExtract_Click()
Dim MyInfo As LinkInfo

MyInfo = GetLinkInfo(Inet1)

End Sub

????????????
 
yes, I wanted the WebBrowser control to navigate and it is working very good. alos I want to navigate without using the browser. but by useing Inet control. how can I write that code ..

thanks alot

Sam
 
I am asking 2many q's sorry. but I just need to get this to work.
this code is poping an error. compile error. argument not optional and .LinkText in the MsgBox line is blue highlighted

Private Sub cmdExtract_Click()
Dim MyInfo As LinkInfo
Dim i As Variant

MyInfo = GetLinkInfo(WB1)

For Each i In MyInfo.LinkText
MsgBox (MyInfo.LinkText & " " & MyInfo.LinkHref)
Next

End Sub
 
I was able to do that last task all right

Private Sub cmdExtract_Click()
Dim MyInfo As LinkInfo
Dim i As Variant
Dim c As Long

c = 1
MyInfo = GetLinkInfo(WB1)
For Each i In MyInfo.LinkText
MsgBox MyInfo.LinkText.Item(c) & " " & MyInfo.LinkHref.Item(c)
c = c + 1
Next

End Sub
 

You could also have used the count
[tt]
Dim I as Integer, MyInfo As LinkInfo

For I = 1 to MyInfo.LinkText.Count
...
[/tt]

Now for the Inet control if you search this site you will find many examples to get it to work. However the code I gave you will not work with a file on disk or a string. You will have to build your own string parser for that.

Glad you got it fixed, Good Luck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top