Posts: 795
Threads: 136
Joined: Feb 2009
Hi
is there a simple way to save to disk an image from a firefox web page after selecting it?
I mess in the html stuff...
Thanks
Posts: 12,086
Threads: 142
Joined: Dec 2002
Easiest - save like you would do it manually: right click, click "Save Image As" ....
Or click "Copy Image Location", then get it from clipboard and download with IntGetFile.
Posts: 12,086
Threads: 142
Joined: Dec 2002
Or let the macro drag drop it to the save folder (an open folder or a folder icon).
Posts: 795
Threads: 136
Joined: Feb 2009
Did not think about the drag and drop thing, seems a good idea.
Any setup canvas to start with?
I already have a toolbar attached to firefox, maybe i can add something to drag the image into, and then
save from there.
If so, can I retreive the url and name of the image when dropped on toolbar?
Thanks
Posts: 12,086
Threads: 142
Joined: Dec 2002
With drag drop much work. I don't know what is format of dropped data.
Add a button that opens the folder and maybe sets always-on-top or owned by Firefox.
Posts: 795
Threads: 136
Joined: Feb 2009
OK, image is alone in web page.
Source containing it is like this:
</td>
<td align='center' valign='middle'>
<a href='http://somesite.com/'>
<img alt='image description' border='0' src='http://some/way/to/file.jpeg'>
</a>
</td>
What is the best solution to get the alt and src content?
How to save to disk and wait for the download is over before ending the macro?
Posts: 12,086
Threads: 142
Joined: Dec 2002
Easier in Internet Explorer. Get Value of accessible object.
In Firefox with accessible object you can get relative path. Need to know base URL. In your example it is full URL, but usually is relative.
IntGetFile has a flag to download to file directly.
Posts: 795
Threads: 136
Joined: Feb 2009
Gintaras Wrote:Easier in Internet Explorer. Get Value of accessible object.
In Firefox with accessible object you can get relative path. Need to know base URL. In your example it is full URL, but usually is relative.
IntGetFile has a flag to download to file directly.
I don't use IE anymore for ages...
The Acc stuff of accessible object is a pain to understand for my brain.
I can see alt and src attribute of accessible object, but it is used to find the object,
i did not understand how to retrieve them.
Help needed here please.
Posts: 12,086
Threads: 142
Joined: Dec 2002
str src=a.WebAttribute("src")
out src
Posts: 795
Threads: 136
Joined: Feb 2009
Great, getting close.
1) Where find the list of all properties WebAttribute can return?
2) how to find src attribute of several images in the same webpage?
Posts: 12,086
Threads: 142
Joined: Dec 2002
1. WebAttribute returns whatever the HTML element has. All that you see in the Find acc object dialog.
2. All images?
Posts: 795
Threads: 136
Joined: Feb 2009
1. OK, useful then.
2. I wish to be able to choose if there are many of them, so yes. Then i'll build
some filters to choose the one(s) i want.
Posts: 12,086
Threads: 142
Joined: Dec 2002
Here is how to get selected HTML.
str s.getsel(0 "HTML Format")
out s
Then extract all using string functions or HtmlDoc class.
Posts: 795
Threads: 136
Joined: Feb 2009
And if I only want to get images or links without any selection?
Posts: 12,086
Threads: 142
Joined: Dec 2002
Get all img src:
Macro Macro1644
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
int i
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
Another very similar way:
Macro Macro1645
int w=wait(2 WV win("Mozilla Firefox" "Mozilla*WindowClass" "" 0x804))
Acc a1.Find(w "DOCUMENT" "" "" 0x3010 2)
str s
a1.WebPageProp(s)
;out s
int i
HtmlDoc d.InitFromWeb(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
In both cases, URLs are relative, with "about:" prefix.
To get all from selection:
Macro Macro1642
Trigger F8
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
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
URLs are full.
Posts: 795
Threads: 136
Joined: Feb 2009
Trying them.
Macro 1644&1645 launches IE when used with Firefox, don't want that
Posts: 12,086
Threads: 142
Joined: Dec 2002
ldarrambide Wrote:Trying them.
Macro 1644&1645 launches IE when used with Firefox, don't want that
Maybe depends on page or some IE settings.
Try this.
Macro Macro1644
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
int i
HtmlDoc d
d.SetOptions(2)
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
Posts: 12,086
Threads: 142
Joined: Dec 2002
WebPageProp gets HTML of whole page. Then HtmlDoc parses the HTML. If HtmlDoc does not work well or is too slow, you can extract everything with string functions, eg findrx.
Posts: 795
Threads: 136
Joined: Feb 2009
This one is perfect.
Just need to be able to find links in selected and non selected state.
Posts: 12,086
Threads: 142
Joined: Dec 2002
Similar. For images we used "img" and "src". For links use "a" and "href".
Posts: 795
Threads: 136
Joined: Feb 2009
Wonderful!!!!
I wonder how one can live without QuickMacros.
You are great Gintaras.
Have some other needs, so i'll open new threads when done.
Kudos.
|