Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Menu selection from dynamic menu
#1
Hi

now that i have all img in the a variable from that code

d.GetHtmlElements(a "img")
for i 0 a.len

i want :

1. filter some url in a new string array, eg a[0]=somelink, a[1]=someother.url
2. create a dynamic menu with a elements as menu items
3. when selected item, do action with url

Possible?
#2
Macro get selected images in Firefox
Code:
Copy      Help
;str s.getclip("HTML Format")
str s.getsel(0 "HTML Format")
;out s
int i=find(s "<html" 0 1); if(i<0) ret
s.get(s i)
;out s; ret

str m

HtmlDoc d.InitFromText(s)
ARRAY(MSHTML.IHTMLElement) a
d.GetHtmlElements(a "img")
for i 0 a.len
,MSHTML.IHTMLElement e=a[i]
,s=e.getAttribute("src" 0)
,;out s
,str name.getfilename(s 1) ;;or try to get title or alt attribute
,m.formata("%s :out ''%s''[]" name s)

;out m
DynamicMenu m
#3
;str s.getclip("HTML Format")
str s.getsel(0 "HTML Format")
;out s
int i=find(s "<html" 0 1); if(i<0) ret
s.get(s i)
;out s; ret

this block does not work at all.

Tweaked with last thread to get it retrieving img tags

int w=wait(2 WV win("Mozilla Firefox" "Mozilla*WindowClass" "" 0x804))
Acc a1.Find(w "DOCUMENT" "" "" 0x3010 2)
str s
a1.WebPageProp(0 0 s)
out s

==================================================================
I can see the selected menu item in QM output window,
but did not get the way to put in str variable.....
#4
If using my previous code, would need to do action in menu item, not in macro. For example, replace out with name of your function that does something with the URL.

Here you get URL in same macro.
Macro menu of images in Firefox
Code:
Copy      Help
int w=wait(2 WV win("Mozilla Firefox" "Mozilla*WindowClass" "" 0x804))
Acc a1.Find(w "DOCUMENT" "" "" 0x3010 2)
str s
a1.WebPageProp(0 0 s) ;;get page HTML
;out s

type NAMEURL str'name str'url
ARRAY(NAMEURL) m ;;array for menu display names and URLs
int i
str sm
MenuPopup p

HtmlDoc d.InitFromText(s)
ARRAY(MSHTML.IHTMLElement) a
d.GetHtmlElements(a "img")
for i 0 a.len
,MSHTML.IHTMLElement e=a[i]
,s=e.getAttribute("src" 0); err continue
,;out s
,
,NAMEURL& r=m[] ;;add array element
,r.name.getfilename(s 1) ;;or try to get title or alt attribute
,r.url=s
,p.AddItems(r.name i+1) ;;add menu item

i=p.Show-1; if(i<0) ret ;;show menu

s=m[i].url
out s
#5
i want complete urls, not relative ones in menu
#6
in AddItems use r.url instead of r.name.
#7
and oddly, i get in Firefox, internet explorer cookie warning stuff Confusedhock:
#8
HtmlDoc uses IE components. With some pages does not work well. Problems with scripts etc. Then instead use findrx or other string functions to extract img tags and their src attribute.

Or use callback function with a1.Find. May be slower with some pages.
#9
Well, i made a macro from last thread using webattribute function which does not mess with
IE.

Can I modify your last code with it?
#10
It was 1 image from mouse? What to modify?
#11
----
int w=wait(1 WV win("- Mozilla Firefox" "Mozilla*WindowClass" "" 0xA04))
Acc a.FindFF(w "IMG" "" "" 0x1000 1)
str src=a.WebAttribute("src")
str alt=a.WebAttribute("alt")
alt.replacerx("/" "-")
alt.replacerx(":" "")
out alt
out src
str dest=F"T:\Laurent\Music\Pochettes\{alt}.jpg"

out dest
DownloadFile(src dest)
#12
If need menu of all images, here is another way.
Macro menu of images in Firefox with callback
Code:
Copy      Help
str s
int w=wait(2 WV win("Mozilla Firefox" "Mozilla*WindowClass" "" 0x804))
Acc a1.FindFF(w "IMG" "" "" 0 0 0 "" &Acc_FindFF_callback_get_img_src &s)
;out s

if(!s.len) ret
int i=ShowMenu(s 0 0 2)-1; if(i<1) ret
s.getl(s i)
out s

;str url; a1.WebPageProp(url) ;;use this if need page URL

also need this function
Function Acc_FindFF_callback_get_img_src
Code:
Copy      Help
;/
function# FFNode&x level str&s FFNODEINFO&ni

;Callback function for Acc.FindFF. Created from a template in File -> New -> Templates menu.

_s=x.Attribute("src")
if(_s.len) s.addline(_s)
ret 1
#13
Still struggling with all your code, slowly marching on.

But i'm very interested in that particular thing:


type NAMEURL str'name str'url
ARRAY(NAMEURL) m

1. Can I store picture in such record array?
2. Can I save to file m for later use?
3. Can m contain data that I declare but can be empty? (str'name str'url str'somenonmandatorytext int'somenumber -> m=name url "" 1025 or m=name url "jjjj" 3020)
4. Can m contain a field which is filled with several urls, maybe str'urls filled with the addline method?

Thanks
#14
1. What format? Can store file path or URL in a member variable of type str.
2. Cannot simply save such array. Need to convert to string: add each element and member to a str variable in some format, and save the str variable. Later open and convert str to array. Maybe easier would be to use ICsv variable, not an array of user defined type like this. Or save to a Sqlite or other database.
3. Yes.
4. Yes, use mutline string, or ARRAY(str) as member.
#15
1. Most web images are gif,png or jpg
2. In far past, i used to use C++, and I could define a custom type of data, containing various different types of
values, and save them to a file. Then i messed with sizeof to get each record in an array, and then find and extract
values i wanted... I don't remember exactly, it's too old.

Any quickmacros approaching technique???
#16
1. A str variable can store file path or data.
2. Similar in QM. Note that string of a str variable is in other memory location.
#17
Gintaras Wrote:1. A str variable can store file path or data.
i'd like to store the image itself in fact.

I'd like to create a file containing the firefox window title, the chosen images in that page, url of the web page, url of the image
and download links i want to save.

type NAMEURL str'title bitmap'image str'url str'imgurl str'links
ARRAY(NAMEURL) m

append m to file.dat
later load file.dat, sizeof(m) loop into each record, find wanted data, and do something with them

maybe a database knowledge would be easier but i don't have time to learn that from scratch...

Gintaras Wrote:2. Similar in QM. Note that string of a str variable is in other memory location.
pfff. i'm too old to dig in that again, and Delphi is way too expensive now.
Will think twice.
#18
For what you need, I would try SQLite database. In QM, use Sqlite class for it.
Or CSV. Then would need to hex-encode image file data. Or store files separately.
#19
Will see if i have spare time.
Focus on primary goal : there is a button on a web page i can find and see properties on accessible object wizard, but the test always fail.

The source code is that, given source url is whatever.com

</div>
<div class="dbutton">
<button type="submit" class="big" onclick="download_file('somefiletoget'); return false;"><span><b><ins class="bigger">go!!</ins></b></span></button>
</div>
</div>

How to find somefiletoget directly from code, as wizard fails?
#20
Macro Macro1652
Code:
Copy      Help
str s=
;</div>
;<div class="dbutton">
;<button type="submit" class="big" onclick="download_file('somefiletoget'); return false;"><span><b><ins class="bigger">go!!</ins></b></span></button>
;</div>
;</div>
;</div>
;<div class="dbutton">
;<button type="submit" class="big" onclick="download_file('otherfiletoget'); return false;"><span><b><ins class="bigger">go!!</ins></b></span></button>
;</div>
;</div>

str rx=
;<button\s+type="submit"\s+class="big"\s+onclick="download_file\('(.+?)'\);
ARRAY(str) a; int i
if(!findrx(s rx 0 1|4 a 1)) end "not found"
for i 0 a.len
,out a[1 i]
#21
great, but somefiletoget or otherfiletoget can vary.

i'd like to be able to store the button attributes instead, onclick especially directly.
#22
yes, can vary.

what other attributes? This macro gets file from onclick attribute of all such buttons.
#23
Damned, i think i loose my time and make loose your because i don't know what to search for, i'm
totally dumb in HTML syntax.
And documentation is too poor for me.
I need to know where are references to datas i can access with all those HTML functions,
as WebPageProp, GetHtmlElements and so..
#24
If a QM function uses something that is [almost] undocumented in function's help, in most cases it is something not QM-specific, and you can find reference on the internet. For example, HTML, CSV, XML, SQL, regular expressions, IHTMLElement, Windows API functions.


Forum Jump:


Users browsing this thread: 2 Guest(s)