I am trying to scrape a stupid page that for some reason changes their 2 input fields ID each time it is run... The only thing that stays the same is the placeholder="xxxx" text.
So I was wondering, is there any way to access the "xxx"? Any other ideas?
THANKS!
IE COM: Getting The placeholder="xxx" text?
Re: IE COM: Getting The placeholder="xxx" text?
Maybe you could use the [Element].getAttribute() method, first reducing if necessary the possible matchs taking advantage of [Document].querySelectorAll() - something like that:
Hope this helps.
Code: Select all
matchingElements := document.querySelectorAll("span.test") ; a first selecting, for example all the span with test as class name
Loop % matchingElements.length
{
if (matchingElements[a_index-1].getAttribute("placeholder") == "xxxx")
{
; ...
break
}
}
Hope this helps.
Re: IE COM: Getting The placeholder="xxx" text?
Thanks. So far what I have done is get all the fields (2), and the first returned I assume is the one I want, and is working. I would try your logic latter.
But, maybe you can help me with this. That same page is returning 10 links to subpages, that are like this:
<button data-ember-action="" data-ember-action-10138="10138">2</button>
How can I get them all, so that I can later do elemen.click? wb.document.getElementsByClassName("button") seems wrong somehow.
But, maybe you can help me with this. That same page is returning 10 links to subpages, that are like this:
<button data-ember-action="" data-ember-action-10138="10138">2</button>
How can I get them all, so that I can later do elemen.click? wb.document.getElementsByClassName("button") seems wrong somehow.
Re: IE COM: Getting The placeholder="xxx" text?
hint
document.querySelector("[placeholder='xxx']")
document.querySelectorAll("[placeholder='xxx']")[0]
document.querySelector("[placeholder='xxx']")
document.querySelectorAll("[placeholder='xxx']")[0]
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
Re: IE COM: Getting The placeholder="xxx" text?
Thanks, would try it.tank wrote:hint
document.querySelector("[placeholder='xxx']")
document.querySelectorAll("[placeholder='xxx']")[0]
Re: IE COM: Getting The placeholder="xxx" text?
Concerning my first answer you can even try this (supposing the placeholder attribute value behaves like an unique ID):
Button is not a class in your exemple; it is a tag name: consider using getElementsByTagName instead:
[EDIT] oops too late...
[EDIT] And in case there is a lot of button in your page you can make the research more selective:
Code: Select all
MyElement := document.querySelector("[placeholder='xxx']") ; get the first element which has actually an placeholder attribute and whose one is xxx
Button is not a class in your exemple; it is a tag name: consider using getElementsByTagName instead:
Code: Select all
buttons := wb.document.getElementsByTagName("button")
buttons[2].click() ; click the third button of the page
[EDIT] oops too late...
[EDIT] And in case there is a lot of button in your page you can make the research more selective:
Code: Select all
document.querySelectorAll("button[data-ember-action='']")
Re: IE COM: Getting The placeholder="xxx" text?
well perhaps but i think you might be mis-underestimating css selectorsA_AhkUser wrote:Button is not a class in your exemple; it is a tag name: consider using getElementsByTagName instead:
document.querySelectorAll("button")[1]
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
Re: IE COM: Getting The placeholder="xxx" text?
@Tank no! and that's why my second edit ; I agree, css selectors are more powerfull. However, I suggested it first thinking it could be usefull for kwanbis using it instead: in order to take things into consideration and name the things by their names: tag, class etc. As for me I used getELementById, getELementsByTagName before uisng querySelector (althought it is not the necessary path). For example:tank wrote:well perhaps but i think you might be mis-underestimating css selectorsA_AhkUser wrote:Button is not a class in your exemple; it is a tag name: consider using getElementsByTagName instead:
document.querySelectorAll("button")[1]
Code: Select all
document.querySelectorAll("button#I[data-ember-action='']")
@ Kwanbis The fact that Tank insists on css selector is relevant and should make you consider take a look at it if you deal with webpage (see: css selectors)
Cheers
Re: IE COM: Getting The placeholder="xxx" text?
Thank you both. I would try to make it work today.
Who is online
Users browsing this forum: Aqualest, gabelynn1, JoeWinograd, Tech Stuff and 155 guests