read links in a webgadget?
read links in a webgadget?
Hello,
How i can read all links from a side what is shown / load in a webgadget?
I want loat all the links from a side into a list but i cant finde a way to read the links.
Thanks
Nico
How i can read all links from a side what is shown / load in a webgadget?
I want loat all the links from a side into a list but i cant finde a way to read the links.
Thanks
Nico
my live space
- netmaestro
- PureBasic Bullfrog
- Posts: 8451
- Joined: Wed Jul 06, 2005 5:42 am
- Location: Fort Nelson, BC, Canada
You can get all the html code in the gadget with something like:
and parse it for links.
Code: Select all
html$ = GetGadgetItemText(#webgadget, #PB_Web_HtmlCode)
BERESHEIT
Hello nicolaus,
for this code you need to include the PureDispHelper
Greetings ... Kiffi
for this code you need to include the PureDispHelper
Code: Select all
; GetLinksFromWebpage
EnableExplicit
Define.l oIE, oDoc, oLink, Result
Define.l CountLinks.l, Counter.l
Define.l InnerText.l, HRef.l
dhToggleExceptions(#True)
oIE = dhCreateObject("InternetExplorer.Application")
If oIE
dhPutValue (oIE, ".Visible = %b", #False)
dhCallMethod(oIE, ".Navigate(%T)", @"www.google.de")
Repeat
dhGetValue("%d", @Result, oIE, ".ReadyState")
Until Result = 4
dhGetValue("%o", @oDoc, oIE, ".Document")
If oDoc
dhGetValue("%d", @CountLinks, oDoc, ".Links.Length")
Debug Str(CountLinks) + " Link(s) available"
Debug "------------"
If CountLinks
For Counter = 0 To CountLinks - 1
dhGetValue("%o", @oLink, oDoc, ".Links(%d)", Counter)
If oLink
dhGetValue("%T", @InnerText, oLink, ".InnerText")
If InnerText
Debug "Link " + Str(Counter + 1) + " (Text): " + PeekS(InnerText)
dhFreeString(InnerText)
EndIf
dhGetValue("%T", @HRef, oLink, ".HRef")
If HRef
Debug "Link " + Str(Counter + 1) + " (Address): " + PeekS(HRef)
dhFreeString(HRef)
EndIf
Debug "------------"
dhReleaseObject(oLink)
EndIf
Next
EndIf
dhReleaseObject(oDoc)
EndIf
dhReleaseObject(oIE)
EndIf
Hygge
@Kiffi
THX that is exactly what i want!
Where i can fined more about disphelper? In your code you have this line
and how i know what is the right method (the second param)?
Greetings
Nico
THX that is exactly what i want!
Where i can fined more about disphelper? In your code you have this line
Code: Select all
dhCallMethod(oIE, ".Navigate(%T)", @"www.google.de")
Greetings
Nico
my live space
you're welcome!PB wrote:Thanks Kiffi, works great!

here is the code using COMate:
Code: Select all
; GetLinksFromWebpage
EnableExplicit
IncludePath #PB_Compiler_Home + "\srod\comate"
XIncludeFile "comate.pbi"
Define oIE.COMateObject, oDoc.COMateObject, oLink.COMateObject
Define CountLinks, Counter
Define InnerText.s, HRef.s
oIE = COMate_CreateObject("InternetExplorer.Application")
If oIE
oIE\SetProperty("Visible = #False")
oIE\Invoke("Navigate('http://www.purebasic.com')")
Repeat
Until oIE\GetIntegerProperty("ReadyState") = 4
oDoc = oIE\getObjectProperty("Document")
If oDoc
CountLinks = oDoc\GetIntegerProperty("Links\Length")
Debug Str(CountLinks) + " Link(s) available"
Debug "------------"
If CountLinks
For Counter = 0 To CountLinks - 1
oLink = oDoc\getObjectProperty("Links(" + Str(Counter) + ")")
If oLink
InnerText = oLink\GetStringProperty("InnerText")
Debug "Link " + Str(Counter + 1) + " (Text): " + InnerText
HRef = oLink\GetStringProperty("HRef")
Debug "Link " + Str(Counter + 1) + " (Address): " + HRef
Debug "------------"
oLink\Release()
EndIf
Next
EndIf
oDoc\Release()
EndIf
oIE\Release()
EndIf
Hygge
Re:
I have a problem with Kiffi's code now. 
When I'm logged into Facebook and I parse this URL for links...
http://www.facebook.com/home.php?sk=lf
...then this block of code always returns 1 for Result (never 4):
Which, as you can tell, means an endless loop.
I did some testing and the return value from dhGetValue is 0.
If I check for that and break out of the loop, then I get this
error box:
What to do?

When I'm logged into Facebook and I parse this URL for links...
http://www.facebook.com/home.php?sk=lf
...then this block of code always returns 1 for Result (never 4):
Code: Select all
Repeat
dhGetValue("%d", @Result, oIE, ".ReadyState")
Until Result = 4
I did some testing and the return value from dhGetValue is 0.
If I check for that and break out of the loop, then I get this
error box:
Code: Select all
---------------------------
Error
---------------------------
Member: .Document
Function: GetValue
Error In: InvokeArray
Error: Unspecified error
Code: 80004005
Source: IDispatch Interface
---------------------------
OK
---------------------------
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
-
- Addict
- Posts: 1482
- Joined: Tue Feb 22, 2011 1:16 pm
Re: Re:
Does anyone know if the example above can be used to get all the image links, rather than hyperlinks, in a page?
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
PureBasic: Born in 1998 and still going strong to this very day!
Re: Re:
see here: http://www.purebasic.fr/english/viewtop ... 12&t=36036MachineCode wrote:Does anyone know if the example above can be used to get all the image links, rather than hyperlinks, in a page?
Greetings ... Kiffi
Hygge
-
- Addict
- Posts: 1482
- Joined: Tue Feb 22, 2011 1:16 pm
Re: Re:
Thanks Kiffi, checking it out now.
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
PureBasic: Born in 1998 and still going strong to this very day!