Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Grab all <H2> within certain DIV
#1
Sorry for this basic question, I have it working using the browser and 'get acc' method.
But I was wondering if it is possible with the below code:
My code below get's all H2, I just need the H2 within the <div class="entry">

Or does the below code has only one method:
Grabbing all <div class="entry"> then put HTML in string and then use regex?
If that is the case, then I can do it. But maybe I overlooked an advanced method or other option within below code?

Macro grab_within_certain_div_example
Code:
Copy      Help
str s
IntGetFile "***WEBSITE URL***" s  ;; CHANGE URL!!!
out
HtmlDoc d.InitFromText(s)
ARRAY(MSHTML.IHTMLElement) h2 div
d.GetHtmlElements(h2 "h2") ;; containerTag, containerNameOrIndex  => Can not set to grab within <div class="entry"> .... ?

int i
out "-----ALL H2-----"
for i 0 h2.len
,str s2=h2[i].innerText
,out s2


;EXAMPLE HTML, NEED TO GRAB ALL H2 WITHIN SPECIFIC: <div class="entry">

;"TEST 1"
;"TEST 2"

;.....
;<BODY>
;<H2>DO NOT GRAB THIS 1</H2>
;<DIV class="entry">
;,<H2>TEST 1</H2>
;</DIV>
;<DIV class="entry">
;,<H2>TEST 2</H2>
;</DIV>
;<H2>DO NOT GRAB THIS 2</H2>
;</BODY>
;.....
;
;
#2
Macro Macro2762
Code:
Copy      Help
str s=
;<BODY>
;<H2>DO NOT GRAB THIS 1</H2>
;<DIV class="entry">
;,<H2>TEST 1</H2>
;</DIV>
;<DIV class="entry">
;,<H2>TEST 2</H2>
;;;;<div><H2>TEST 3</H2></div>
;</DIV>
;<H2>DO NOT GRAB THIS 2</H2>
;</BODY>

out
HtmlDoc d.InitFromText(s)
ARRAY(MSHTML.IHTMLElement) h2 div
int i j
d.GetHtmlElements(div "div")
for i 0 div.len
,str cn=div[i].className
,if cn="entry"
,,d.GetHtmlElements(h2 "h2" "" div[i].sourceIndex)
,,for j 0 h2.len
,,,out h2[j].innerText
#3
Wow! thank you!


Forum Jump:


Users browsing this thread: 1 Guest(s)