Code: Select all
text := wb.document.documentElement.innerText
Code: Select all
<h1 class="title inline-block">
Google
</h1>
Code: Select all
text := wb.document.documentElement.innerText
Code: Select all
<h1 class="title inline-block">
Google
</h1>
Code: Select all
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := True
wb.Navigate("www.autohotkey.com/boards/")
WaitForLoad(wb)
Text := wb.document.getElementsByClassName("username-coloured")[0].innerText
MsgBox, % Text
return
WaitForLoad(wb)
{
while wb.busy or wb.ReadyState != 4
Sleep, 10
}
Awesome, thanks so much this is very informative and very helpful. A couple follow up guestions:boiler wrote: ↑12 Nov 2019, 00:08If you want to get the text from a single element, you need to use something other than wb.document.documentElement.innerText which gets you all the text on the page. You could just grab all the text (or the html by using innerHTML) and parse it to find what you want, but you're usually better off finding specific elements directly. See this example for getting the first "coloured" username (such as an admin) on the AHK forum page:
So you could substitute your URL and the name of the class you're looking for ("title inline-block"), and it will return "Google" if it's the first one of that class on the page. If not, increment the index on the array from 0 until you find it.
Code: Select all
data-control-name="topcard_employees"
Code: Select all
<a data-control-name="topcard_employees" href="/sales/search/people/list/employees-for-account/23521" id="ember971" class="ember-view"> 46,036 employees
</a>
Code: Select all
<a data-control-name="topcard_employees" href="/sales/search/people/list/employees-for-account/10667" id="ember971" class="ember-view"> 46,036 employees
</a>
Actually, data-... is a custom attribute, and you could identify that node with something like wb.document.querySelectorAll("[data-control-name=""topcard_employees""]"), but don't have a lot of experience with it, and I find it difficult to get the data I want using that.3ggg wrote: ↑ I assume for the code below you'd have to do a different strategy than get element by class name since there's multiple hundred "ember-views" in the page. May be clueless here but I guess the identifier here would beI assume this would be a get element by ( blank ) but I don't know what that blank isCode: Select all
data-control-name="topcard_employees"
Code: Select all
<a data-control-name="topcard_employees" href="/sales/search/people/list/employees-for-account/23521" id="ember971" class="ember-view"> 46,036 employees </a>
Yes, generally that will give you the link URL if there is one associated with it.
Since it has an id, that is a unique identifier which can be selected by getElementById. Note that since it returns a single element, there is no array indexing. So it looks like this:3ggg wrote: ↑12 Nov 2019, 00:59I assume we can't use getelementbyclassID and you have to use getelementby something else. I assume data-control-name="topcard_employees" is the unique piece here but I'm unsure what element type this is?Code: Select all
<a data-control-name="topcard_employees" href="/sales/search/people/list/employees-for-account/10667" id="ember971" class="ember-view"> 46,036 employees </a>
Code: Select all
text := wb.document.getElementByID("ember-view").innerText
Users browsing this forum: Bing [Bot], Google [Bot], Mateusz53, MrHue, mstrauss2021, Rohwedder and 310 guests