Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Manipulating Table In A Website
#3
I guess you want to get text of cells in the table. Can be used several ways.

1. Select the table manually, get selected text (getsel), and parse it (findrx or tok). But I don't know is it reliable. Cells are separated by two spaces, but cell contents also may contain two spaces... Also, text parsing is not easy.

2. Find the table using htm, and get its html (HTML). Then parse (findrx). It would be reliable but even more difficult. Also, does not work in firefox.

3. Find first cell as accessible object (acc) and get other cells using accessible object navigation. This is reliable and not very difficult. You only have to read about accessible object navigation in QM help. Works on IE and FF, however something is different.

Macro for IE

Code:
Copy      Help
;This macro works in IE.

ClearOutput
;Find first cell (containing useful information) in the table.
;Since its contents is undefined, capture some object above
;the table and navigate to the cell. In the example is used
;navigation string "parent next7 first". You can discover the
;string, as well as other navigation strings, by looking at
;the object tree in the 'Find accessible object' dialog and
;experimenting with the Navigate field.

Acc a=acc("Order #" "TEXT" win(" Internet Explorer" "IEFrame") "Internet Explorer_Server" "" 0x1801 0x40 0x20000040 "parent next7 first")
;Now walk through the table using accessible object navigation
int i r
;For each row
rep ;;I don't know how many rows there are, so use rep and later break on error
,r+1; out "--- row %i ---" r
,;For each cell
,for i 0 5 ;;I know the number of columns. It is 5 (Order #, Customer, Date, Total, Sales Rep)
,,str s=a.Name
,,out s
,,if(i!=4) a.Navigate("parent next first") ;;get next cell
,;get first cell in next row
,a.Navigate("parent next6 first")
,err break ;;if error, there are no more rows
,

Macro for FF

Code:
Copy      Help
;This macro works in FF.

ClearOutput
;Find first cell (containing useful information) in the table.
;Since its contents is undefined, capture some object above
;the table and navigate to the cell. In the example is used
;navigation string "parent next7 first". You can discover the
;string, as well as other navigation strings, by looking at
;the object tree in the 'Find accessible object' dialog and
;experimenting with the Navigate field.

Acc a=acc("Order #" "TEXT" win("Mozilla Firefox" "MozillaUIWindowClass") "MozillaContentWindowClass" "" 0x1801 0x40 0x20000040 "parent next7 first")
;Now walk through the table using accessible object navigation
int i r
;For each row
rep ;;I don't know how many rows there are, so use rep and later break on error
,r+1; out "--- row %i ---" r
,;For each cell
,for i 0 5 ;;I know the number of columns. It is 5 (Order #, Customer, Date, Total, Sales Rep)
,,str s=a.Name
,,out s
,,if(i!=4) a.Navigate("parent next first") ;;get next cell
,;get first cell in next row
,a.Navigate("parent next3 first")
,err break ;;if error, there are no more rows
,

The same with array

Code:
Copy      Help
;This macro gets table cells to 2-dim array.
;Works in IE and FF.


int ff
;ff=1 ;;enable this for firefox

ClearOutput

;Create empty 2-dim array.
ARRAY(str) ar.create(5 0)
;Get first cell.
Acc a
if(ff) a=acc("Order #" "TEXT" win("Mozilla Firefox" "MozillaUIWindowClass") "MozillaContentWindowClass" "" 0x1801 0x40 0x20000040 "parent next7 first")
else a=acc("Order #" "TEXT" win(" Internet Explorer" "IEFrame") "Internet Explorer_Server" "" 0x1801 0x40 0x20000040 "parent next7 first")
;Walk through the table.
int c r
for r 0 1000000 ;;for each row
,ar.redim(-1) ;;add empty elements for 1 row
,
,for c 0 5 ;;for each cell in the row
,,ar[c r]=a.Name
,,if(c!=4) a.Navigate("parent next first")
,,
,a.Navigate(iif(ff "parent next3 first" "parent next6 first"))
,err break

;Show results.
for r 0 ar.len(2)
,out "--- row %i ---" r+1
,for c 0 ar.len(1)
,,str s=ar[c r]
,,out s
,,

These macros work in the page you emailed me (see the attached image). The output is

Code:
Copy      Help
--- row 1 ---
2660
c, k  
9/12/2007 4:45:00 PM
USD $23.80

--- row 2 ---
2659
M, N
9/12/2007 4:17:00 PM
USD $14.00

--- row 3 ---
2658
l, a
9/12/2007 3:43:00 PM
USD $42.00

--- row 4 ---
2657
p, s
9/12/2007 2:53:00 PM
USD $28.00


Attached Files Image(s)
       


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)