Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Enumerate Elements on webpage
#1
This works, but is super sloppy. Any ideas how to make something like this?

Code:
Copy      Help
opt err 1
str s
IntGetFile "http://www.google.com" s
out
s.findreplace("<img" "<img id=xImageX" 1)
s.findreplace("href" "id=xlinkX href" 1)
s.findreplace(">" ">[]")
ARRAY(str) Images Links
for _i 0 numlines(s)
,_s.getl(s _i)
,HtmlDoc d.InitFromText(_s)
,if Links[Links.len]=Links[Links.len-1]
,,Links.remove(Links.len)
,if !(Links[Links.len-1].len)
,,Links.remove(Links.len-1)
,if Images[Images.len]=Images[Images.len-1] and (!Images[Images.len].len)
,,Images.remove(Images.len)
,if !(Images[Images.len-1].len)
,,Images.remove(Images.len-1)

,Images[]=d.d3.getElementById("xImageX").getAttribute("src" 2)
,Links[]=d.d3.getElementById("xlinkX").getAttribute("href" 2)

out "-----Links-----"
out Links
out "-----Images----"
out Images

Thanks,
Jimmy Vig
#2
Macro Macro1443
Code:
Copy      Help
str s
IntGetFile "http://www.google.com" s
out
HtmlDoc d.InitFromText(s)
ARRAY(MSHTML.IHTMLElement) aLinks aImages
d.GetHtmlElements(aLinks "a")
d.GetHtmlElements(aImages "img")

int i
out "-----Links-----"
for i 0 aLinks.len
,out aLinks[i].getAttribute("href" 2)
out "-----Images----"
for i 0 aImages.len
,out aImages[i].getAttribute("src" 2)
#3
Thanks
#4
Gintaras,

Any ideas to make this better?
Member function str.Html
Member function str.Html
Code:
Copy      Help
function str'Html str'Element str'Attibute [int'Index] [str&Results]

;EXAMPLE
;str s
;IntGetFile "http://www.google.com" s
;str Results
;str x.Html(s "a" "href" 5 Results)
;
;out x
;out "------"
;out Results

HtmlDoc d.InitFromText(Html)
ARRAY(MSHTML.IHTMLElement) aHtml
d.GetHtmlElements(aHtml Element)

for _i 0 aHtml.len
,Results+aHtml[_i].getAttribute(Attibute 2)
,if !(_i=aHtml.len-1)
,,Results+"[]"
this=aHtml[Index].getAttribute(Attibute 2);err ret 1
Definitely works for me in a lot of cases where I use to put a lot of code!
#5
One thing is...I didn't notice but if you don't use "Results" in function get error: invalid pointer

How would you make the complete results available in the caller function without making it a required variable to pass.
I would just like to be able to use short versions of this to get an specific index and still have the option to grab all the results.

Thanks,
Jimmy Vig
#6
Member function str.Html
Code:
Copy      Help
function $Html $Tag $Attibute [Index] [str&Results]

;EXAMPLE
;str s
;IntGetFile "http://www.google.com" s
;str Results
;str x.Html(s "a" "href" 5 Results)
;
;out x
;out "------"
;out Results

if(&Results) Results.fix(0)

HtmlDoc d.InitFromText(Html)
ARRAY(MSHTML.IHTMLElement) aHtml
d.GetHtmlElements(aHtml Tag)

if &Results
,for(_i 0 aHtml.len) Results.AddLine(aHtml[_i].getAttribute(Attibute 2))
,Results.rtrim("[]")

this=aHtml[Index].getAttribute(Attibute 2)

err+ ret 1
#7
Thanks!!

========================
Results.AddLine
Results.addline


Forum Jump:


Users browsing this thread: 1 Guest(s)