Jump to content


Photo

COM for Webpages help needed


  • Please log in to reply
14 replies to this topic

#1 janopn

janopn
  • Members
  • 691 posts

Posted 09 May 2012 - 01:05 PM

Hi!
I've just started using COM for webpages and i'm trying to understand some things.
I'm using This great tutorial, and i use ahk web recorder, but i have some doubts.

1) -SOLVED!- I know how to click buttons that have an associated Name on the ahk web recorder. But, if they don't?
I have a button with no "Name" value (in ahk web recorder). I have the ID and the Index value. Can't i simulate a click with the ID information? or Index?

The iWeb example is:

iWeb_setDomObj(pwb,"dp_submit","recherchez")

ID is "dp_submit", and index is 347. ALWAYS.

I have also the Outer HTML:

<INPUT id=dp_submit class=siteBtn title=recherchez value=recherchez type=submit>

I know this is enough information to just press a button, but i'm new so help me handle it :)




2) -SOLVED!- Once i click that button another webpage with information will appear.
I need to take the value of a field there but it has no Name.
This piece of information is insde a block of a table.

Outer HTML:
<STRONG class=115600>1156,00 €*</STRONG>

The Value/Inner Text is "1156,00 €*"
That price is the value i need to take!

As you can see, the outer html contains the value too.

But i don't know how to get it.


So please, help me to understand how to call iWeb functions with the parametres i got from the recorder (if i just try to call the function as ahk recorder says, i got the "non existent fuction" error), and how to get a value inside a table.

Thanks a lot for your time :)

#2 0x150--ISO

0x150--ISO
  • Members
  • 657 posts

Posted 09 May 2012 - 01:24 PM

For question 1 this works for me
object.document.forms[0].submit()
Sorry just I noticed your using a function for this.
So the parameters may be entirely different.

#3 janopn

janopn
  • Members
  • 691 posts

Posted 09 May 2012 - 01:37 PM

Perfect! Works like charm :)
So, placing at "forms" i can call the submit method and is like pressing enter, right?

What is the [0] in forms?

Thanks a lot, now i have to manage up with the second step, retrieveng a value..
Do i have to post more info?

#4 Blackholyman

Blackholyman
  • Members
  • 1230 posts

Posted 09 May 2012 - 01:43 PM

I don't use the iweb function's but for question 1 you can also use
iWeb_clickDomObj(pwb,"dp_submit")
or this
object.document.GetElementById("dp_submit").click()
:)

for question 2 im not sure but maybe with more info like the index number :(


#5 tank

tank
  • Members
  • 4110 posts

Posted 09 May 2012 - 01:44 PM

Hi i didnt think anyone was still using this library

first of all yes the function accepts the name or id or index

but i dont think it is wiser than doing this (old com library which you are apparently using which is fine)
com_invoke(pwb, "document.getelementbyid('dp_submit').click()")
as far as the amount does it have a consistent index?
msgbox % com_invoke(pwb, "document.all[[color=#FF0000]n[/color]].innertext")

edit i see that your able to use the _L syntax
in my mind the iweb library is useless compared to the ease of using DOM directly

#6 janopn

janopn
  • Members
  • 691 posts

Posted 09 May 2012 - 02:01 PM

Hi tank,
Hi Blackholyman,
thanks for the quick reply!

I quite don't know what is "new" and what's "old" in this.
The com_invoke gives me the "call to non existent function", sabe with the Iweb functions.

I don't know if there is a problem with my ahk (i'm at work and i don't have full permissions, so maybe is that).

The thing is that if i try to call those functions, i got the "Non existent" error.

Meanwhile, handling the first request with object.document... is working really well :)


About the 2nd request:
I'm trying to use the script to get a price of a flight.
Once i click the Search button (first request), another web with many prices is shown.
I need the first price. (from up to down).

The prices are shown in a table (ahk web recorder recognizes it as a table, and it is visible as a table).
In the same chart we have some other information, such as come back date, airplane company, etc.

I leave you a screenshot:

Posted Image

I hope you understand a little more now :)

Now i will leave you all the ahk web recorder info i can get.
The Outer HTML are quite longs, many rows of information.

The Outer HTML of the row of that table is:

<TABLE class=tableFlight cellSpacing=5 summary="" cellPadding=0><TBODY>
<TR>
<TD id=ctl00_m_cphMain_m_ctrlFlightResults_m_ctrlFlightListResult_m_rptResults_ctl00_td_company class=companyCol rowSpan=2><A class=showDetailsPopin href="/FlightPopinCompany.aspx?CompanyName=American_Airlines&ProductTypeCode=RP&idpart=944547" rel=a-1 jQuery16408960390251871857="1"><IMG class=img_Company alt="American Airlines ," onerror="javascript: this.src = '/img/Flights/noCie-small.GIF';" src="/img/Flights/AA_small.gif" width=95 height=15></A> </A><BR></TD>
<TD class=departCol>jeu. 17/05 </TD>
<TD class=returnCol>sam. 19/05 </TD>
<TD class=escaleCol abbr=INDIRECT><SPAN>1 escale(s)</SPAN> </TD>
<TD class=priceCell><SPAN class=oldPrice>1223,00 €</SPAN> </TD>
<TD class=discountCol><STRONG class=discount>-18 €</STRONG> </TD>
<TD class=totalCol>
<P class=totalTTC><STRONG class=120500>[color=red]1205,00 €*[/color]</STRONG><BR><SPAN>(<A onclick="showResultTarif(this.href); return false;" href="/popinFlightTarifStep2.aspx?navid=5d8ecbc8-e889-4aed-8d1f-25239cbc6b7a&idpart=944547&prop=1">détail du tarif</A>)</SPAN></P></TD>
<TD class=actionCol>
<DIV class=clearfix><A class="button showOtherChoice" href="#" rel=#otherFlights1|Visualiser|Masquer jQuery16408960390251871857="129"><SPAN>Visualiser</SPAN></A></DIV></TD></TR></TBODY></TABLE>

In red is the price, the value i need to get.

More info required?

Thanks a lot, this is part of a good script for another request, and i'm taking advantage of this to learn COM :)

Thanks again!

#7 sinkfaze

sinkfaze
  • Moderators
  • 6089 posts

Posted 09 May 2012 - 02:16 PM

You may as well just try downloading the source contents of the page and match it via regex:

RegExMatch(COM_Invoke(pwb, "document.documentElement.outerHTML"),"totalTTC><STRONG class=\d+>\K[color=#FF0000][^<]+[/color]",amount)
MsgBox %	amount


#8 janopn

janopn
  • Members
  • 691 posts

Posted 09 May 2012 - 02:19 PM

Hi skinfaze! Thanks for the reply!
I still get errors while calling COM_Invoke or iWeb functions :/
Are they all included in AHK_L, right?

#9 Blackholyman

Blackholyman
  • Members
  • 1230 posts

Posted 09 May 2012 - 02:23 PM

None of them are in _L just the raw syntex :) you'll need to add Them if you need them...

#10 sinkfaze

sinkfaze
  • Moderators
  • 6089 posts

Posted 09 May 2012 - 02:25 PM

The iWeb functions are not wholly functional for the latest releases of AHK_L; when AHK_L really started pumping out substantial upgrades we decided to hold off on updates to the iWeb functions until the dust settled. Once it did our interests had gone elsewhere, but in reality the changes made in AHK_L are enough that in most cases the iWeb functions aren't much cleaner than writing the direct code (although I can still see a benefit to some of them, like the table and tag functions).

So my same code in AHK_L for you to try:

RegExMatch(pwb.document.documentElement.outerHTML,"totalTTC><STRONG class=\d+>\K[^<]+",amount)
MsgBox %   amount


#11 0x150--ISO

0x150--ISO
  • Members
  • 657 posts

Posted 09 May 2012 - 02:27 PM

What is the [0] in forms?

Happens to be the 1st and only index.
I think its universal but if it does fail you could try to loop thru until you find the index with the form.

...I still get errors while calling COM_Invoke or iWeb functions :/
Are they all included in AHK_L, right?

Yea native COM in _L is a much better IMO. I'm weary of using more than one approach @ the same time.
wait what do you mean by "they"??

..most cases the iWeb functions aren't much cleaner than writing the direct code..

Agreed! Plus you get a much better understanding of what goes on under the hood.

#12 janopn

janopn
  • Members
  • 691 posts

Posted 09 May 2012 - 02:40 PM

Too many replies! Thanks a lot! :)

1)Blackholyman:

Oh, ok, i see. Good to know, i will look for them in the forum :)
Thanks!

2)0x150||ISO:

Oh, ok. Just like a general formula, good to know.
Thanks!

3)sinkfaze:

Ohhh, now i understand how to reach different parts of the document!
That regex worked perfectly!
I have to erase the " " and "*" now, so i get the price :)

So that would be all!

I just found out that i have the same price in a particular part of the web, under the ID of "sp_minPrice".
I tried to get that value by this command:

pwb.document.GetElementById("sp_minPrice").InnerText

As someone left before how to use the ID.
It worked, so it's great!

Thanks a lot, to all, really!

#13 0x150--ISO

0x150--ISO
  • Members
  • 657 posts

Posted 09 May 2012 - 02:47 PM

I have to erase the " " and "*" now, so i get the price :)

RegExMatch(pwb.document.documentElement.outerHTML, "totalTTC><STRONG class=\d+>\K([\d,]+)[\w&;]+(\W)[^<]+", m ), amount := m2 " " m1

MsgBox %   amount
;) Unicode only ofcourse

#14 janopn

janopn
  • Members
  • 691 posts

Posted 09 May 2012 - 02:52 PM

Oh, thanks a lot, 0x150||ISO.
I have to learn to manage strings and regex still :)

Officialy solved!

Thanks a lot everybody. A pleasure being here with you.

#15 sinkfaze

sinkfaze
  • Moderators
  • 6089 posts

Posted 09 May 2012 - 02:59 PM

This should do it:

RegExMatch(pwb.document.documentElement.outerHTML,"totalTTC><STRONG class=\d+>\K[^<]+",amount)
MsgBox %	RegExReplace(amount,[color=#FF0000]" |\*"[/color])