how to save all text from html Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
blackie
Posts: 12
Joined: 02 Jul 2021, 21:50

how to save all text from html

Post by blackie » 02 Aug 2021, 22:41

Hi all, I am trying to get informations from an html file. I got an example from https://www.autohotkey.com/boards/viewtopic.php?t=74050 but it shows first result only. I want all result from HTML file. My current script is below. Thanks in advance. :roll:

Code: Select all

numpad1::
H =
(
....
<span class="pv-test-category-entity__name-text t-16 t-black t-bold"> Wellness  </span> ... </a><!---->  
  </p>   <span class="pv-test-category-entity__name-text t-16 t-black t-bold"> Nutrition Education</span></a><!---->    </p>   
   ...  <span class="pv-test-category-entity__name-text t-16 t-black t-bold">  Research  </span>
</a>
<!---->    </p>  ...   <span class="pv-test-category-entity__name-text t-16 t-black t-bold">  Sports Nutrition   </span>
</a>
<!---->    </p> ...
...
)

B   := "name-text t-16 t-black t-bold"">"     ; Begin match
E   := "</span>"      ; End match
P1  := InStr(H, B)     ; Position of Begin match 
P2  := InStr(H, E)         ; Position of End match
Res := SubStr(H, P1:=P1+StrLen(B), P2-P1)
sleep, 200
msgbox %Res% ; shows Wellness only. but I want Nutrition Education, Research, Sports Nutrition etc.
;fileappend, %Res%, test.txt
return
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: how to save all text from html

Post by AHKStudent » 03 Aug 2021, 01:34

Code: Select all

HTML =
(
....
<span class="pv-test-category-entity__name-text t-16 t-black t-bold"> Wellness  </span> ... </a><!---->  
  </p>   <span class="pv-test-category-entity__name-text t-16 t-black t-bold"> Nutrition Education</span></a><!---->    </p>   
   ...  <span class="pv-test-category-entity__name-text t-16 t-black t-bold">  Research  </span>
</a>
<!---->    </p>  ...   <span class="pv-test-category-entity__name-text t-16 t-black t-bold">  Sports Nutrition   </span>
</a>
<!---->    </p> ...
...
)
document := ComObjCreate("HTMLfile")
document.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=EDGE"">")
document.designMode := "on"
document.write(HTML)
MsgBox, % document.body.innerText
ExitApp
blackie
Posts: 12
Joined: 02 Jul 2021, 21:50

Re: how to save all text from html

Post by blackie » 03 Aug 2021, 01:59

Hi AHKStudent, Thank you for your effort. :clap: Unfortunately I am still on it. Is there any way to get the text between name-text t-16 t-black t-bold"> and </span>. Because my HTML file has too many inner text that I don't want. :)
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: how to save all text from html  Topic is solved

Post by AHKStudent » 03 Aug 2021, 03:00

blackie wrote:
03 Aug 2021, 01:59
Hi AHKStudent, Thank you for your effort. :clap: Unfortunately I am still on it. Is there any way to get the text between name-text t-16 t-black t-bold"> and </span>. Because my HTML file has too many inner text that I don't want. :)

Code: Select all

HTML =
(
....
<span class="pv-test-category-entity__name-text t-16 t-black t-bold"> Wellness  </span> ... </a><!---->  
  </p>   <span class="pv-test-category-entity__name-text t-16 t-black t-bold"> Nutrition Education</span></a><!---->    </p>   
   ...  <span class="pv-test-category-entity__name-text t-16 t-black t-bold">  Research  </span>
</a>
<!---->    </p>  ...   <span class="pv-test-category-entity__name-text t-16 t-black t-bold">  Sports Nutrition   </span>
</a>
<!---->    </p> ...
...
)
document := ComObjCreate("HTMLfile")
document.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=EDGE"">")
document.designMode := "on"
document.write(HTML)
ele := document.getElementsByClassName("pv-test-category-entity__name-text") ; the class name
loop, % ele.length ; how many such classes are there and loop over them
	info .= ele[a_index -1].innerText "`n" ; get the inner text of those classes
MsgBox, % info
ExitApp
blackie
Posts: 12
Joined: 02 Jul 2021, 21:50

Re: how to save all text from html

Post by blackie » 03 Aug 2021, 04:54

Well done. Thanks. That makes the day! :bravo: :bravo:
Post Reply

Return to “Ask for Help (v1)”