Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Web Image saving
#1
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
#2
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.
#3
Or let the macro drag drop it to the save folder (an open folder or a folder icon).
#4
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
#5
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.
#6
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?
#7
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.
#8
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.
#9
str src=a.WebAttribute("src")
out src
#10
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?
#11
1. WebAttribute returns whatever the HTML element has. All that you see in the Find acc object dialog.
2. All images?
#12
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.
#13
Here is how to get selected HTML.

str s.getsel(0 "HTML Format")
out s

Then extract all using string functions or HtmlDoc class.
#14
And if I only want to get images or links without any selection?
#15
Get all img src:
Macro Macro1644
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)
;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
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(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     Help - how to add the trigger to the macro
Code:
Copy      Help
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.
#16
Trying them.

Macro 1644&1645 launches IE when used with Firefox, don't want that
#17
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
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)
;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
#18
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.
#19
This one is perfect.

Just need to be able to find links in selected and non selected state.
#20
Similar. For images we used "img" and "src". For links use "a" and "href".
#21
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.


Forum Jump:


Users browsing this thread: 2 Guest(s)