Choose pdf name dynamically by variable does not work, datetime only

Discussions and Tech Support related to website data extraction, screen scraping and data mining using iMacros.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information:CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
Program
Posts: 10
Joined: Wed Jan 10, 2018 4:05 pm

Choose pdf name dynamically by variable does not work, datetime only

Post by Program » Mon Dec 24, 2018 1:36 am

Dear friends,

Imacros Version: 10.0.5
Chrome: Versão 71.0.3578.98
OS: Windows 10 64 bits

I trying download some open pdf's in som sites, for example here I will put this site:
https://www.wdl.org/pt/item/18529/

So the title of this page is "Valência. Mercado", I want extract the title of many pages to put in pdf name when downloaded.

My script working with dynmi datetime:

Code: Select all

TAG POS=1 TYPE=H1 ATTR=ID:page-title EXTRACT=TXT
SET !VAR1 {{!EXTRACT}}
TAG SELECTOR="#downloads>LI>A"
ONDOWNLOAD FOLDER=* FILE=+_{{!NOW:yyyymmdd_hhnnss}} WAIT=YES
TAG SELECTOR="#downloads>LI>UL>LI:nth-of-type(2)>A"

So, when I download using this above code, the name of archive comes: "18529_20181223_223412", this proof that the datetime dynamicaly works.

But when I try put the title page as filename dinamycaly (to work in another pages), dont work, see my script:

Code: Select all

TAG POS=1 TYPE=H1 ATTR=ID:page-title EXTRACT=TXT
SET !VAR1 {{!EXTRACT}}
TAG SELECTOR="#downloads>LI>A"
ONDOWNLOAD FOLDER=* FILE=+_{{!VAR1}} WAIT=YES
TAG SELECTOR="#downloads>LI>UL>LI:nth-of-type(2)>A"
I thinks must be some simple action to solve this (because the dynamic datetime works, some the name by variable must work by logical thinking), I try many things and dont work, someone can help with this?

thanks in advanced
chivracq
Posts: 8525
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Choose pdf name dynamically by variable does not work, datetime only

Post by chivracq » Mon Dec 24, 2018 2:19 am

Program wrote:
Mon Dec 24, 2018 1:36 am
Dear friends,

Code: Select all

Imacros Version: 10.0.5
Chrome: Versão 71.0.3578.98
OS: Windows 10 64 bits
I trying download some open pdf's in som sites, for example here I will put this site:
https://www.wdl.org/pt/item/18529/

So the title of this page is "Valência. Mercado", I want extract the title of many pages to put in pdf name when downloaded.

My script working with dynmi datetime:

Code: Select all

TAG POS=1 TYPE=H1 ATTR=ID:page-title EXTRACT=TXT
SET !VAR1 {{!EXTRACT}}
TAG SELECTOR="#downloads>LI>A"
ONDOWNLOAD FOLDER=* FILE=+_{{!NOW:yyyymmdd_hhnnss}} WAIT=YES
TAG SELECTOR="#downloads>LI>UL>LI:nth-of-type(2)>A"
So, when I download using this above code, the name of archive comes: "18529_20181223_223412", this proof that the datetime dynamicaly works.

But when I try put the title page as filename dinamycaly (to work in another pages), dont work, see my script:

Code: Select all

TAG POS=1 TYPE=H1 ATTR=ID:page-title EXTRACT=TXT
SET !VAR1 {{!EXTRACT}}
TAG SELECTOR="#downloads>LI>A"
ONDOWNLOAD FOLDER=* FILE=+_{{!VAR1}} WAIT=YES
TAG SELECTOR="#downloads>LI>UL>LI:nth-of-type(2)>A"
I thinks must be some simple action to solve this (because the dynamic datetime works, some the name by variable must work by logical thinking), I try many things and dont work, someone can help with this?

thanks in advanced
FCI mentioned, perfect..., but when using v10.x for FF/CR, you need to mention also if you are using the 'Free' or 'PE' Version... Hum, and especially when downloading Files, as the 'FOLDER' Parameter for example (from the 'ONDOWNLOAD' Command) is not supported in the 'Free' Versions...

But, hum, I notice that your 'EXTRACT' contains some Soft Returns from the 'H1' Element on that Page..., and which the OS or Browser probably won't accept as valid Chars for a Filename..., try this one:

Code: Select all

TAG POS=1 TYPE=H1 ATTR=ID:page-title EXTRACT=TXT
'SET !VAR1 {{!EXTRACT}}
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var z=s.trim(); z;")
'PROMPT _{{!VAR1}}_
'>
TAG SELECTOR="#downloads>LI>A"
ONDOWNLOAD FOLDER=* FILE=+_{{!VAR1}} WAIT=YES
TAG SELECTOR="#downloads>LI>UL>LI:nth-of-type(2)>A"
WAIT SECONDS=1
(Not tested (or only until the 'PROMPT' => on iMacros for FF v8.8.2, PM v26.3.3 (=FF47), Win10_x64), as the 'TAG SELECTOR' Syntax is only supported in v10.x for CR...)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Program
Posts: 10
Joined: Wed Jan 10, 2018 4:05 pm

Re: Choose pdf name dynamically by variable does not work, datetime only

Post by Program » Mon Dec 24, 2018 10:07 pm

Dear Chivracq, I'm using addon free, and your suggestion worked, thank you.
I figured it should work since datetime dynamically works, thanks for the support, have a merry christmas and a great new year
chivracq
Posts: 8525
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Choose pdf name dynamically by variable does not work, datetime only

Post by chivracq » Tue Dec 25, 2018 4:07 am

Program wrote:
Mon Dec 24, 2018 10:07 pm
Dear Chivracq, I'm using addon free, and your suggestion worked, thank you.
I figured it should work since datetime dynamically works, thanks for the support, have a merry christmas and a great new year
Oh...!, good to hear...! :D

I wasn't completely-completely sure it would work "for you" as well (well, I had not been able to check on the File for the Download because of the 'SELECTOR' Parameter not being supported for the 'TAG' Command in the Version that I usually use), and because the 'trim()' Function I had used in the 'EVAL()' is no "Standard" JS Function, not supported in all Browsers..., but apparently it is in CR also..., OK, good-good-good...! :wink:

(And Thanks for the Feedback/Follow-up, of course... :wink: )
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Program
Posts: 10
Joined: Wed Jan 10, 2018 4:05 pm

Re: Choose pdf name dynamically by variable does not work, datetime only

Post by Program » Thu Dec 27, 2018 1:32 am

Dear

I have a new problem, I test the last code in a new page, I use the prompt option to see the result, I try some Eval, and even dont work.
I try simplificate more, put Hello world in variable Var1

Code: Select all

SET !VAR1 Hello<SP>World
PROMPT _{{!VAR1}}_
ONDOWNLOAD FOLDER=* FILE=+_{{!VAR1}} WAIT=YES
TAG SELECTOR="#step5>A:nth-of-type(2)"
WAIT SECONDS=1
when I run this code in another site (with login and password, private site) and I try put name Hello World dont work. In promp appear ok the string, prompt show:
"_Hello World_"

But even dont work in the filename, the pdf comes with original name:
"12734.pdf"

How I can debug and discover the problem in these cases?

I try another ways, without SELECTOR, for example change
TAG SELECTOR="#step5>A:nth-of-type(2)"

to

TAG POS=1 TYPE=I ATTR=CLASS:fa<SP>fa-4x

and the pdf comes with original name, I believe selector is not the problem, in these new site for some reason the Var1 in filename dont work, nad I want learn how to discover (debug) the reason of that. Pls, can you give some tips?

Thanks
Last edited by Program on Fri Jan 04, 2019 2:35 am, edited 1 time in total.
chivracq
Posts: 8525
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Choose pdf name dynamically by variable does not work, datetime only

Post by chivracq » Thu Dec 27, 2018 1:49 am

Program wrote:
Thu Dec 27, 2018 1:32 am
Dear

I have a new problem, I test the last code in a new page, I use the prompt option to see the result, I try some Eval, and even dont work.
I try simplificate more, put Hello world in variable Var1

Code: Select all

SET !VAR1 Hello<SP>World
PROMPT _{{!VAR1}}_
ONDOWNLOAD FOLDER=* FILE=+_{{!VAR1}} WAIT=YES
TAG SELECTOR="#step5>A:nth-of-type(2)"
WAIT SECONDS=1
when I run this code in another site (with login and password, private site) and I try put name Hello World dont work. In promp appear ok the string, prompt show:
"_Hello World_"

But even dont work in the filename, the pdf comes with original name:
"56754.pdf"

How I can debug and discover the problem in these cases?

I try another ways, without SELECTOR, for example change
TAG SELECTOR="#step5>A:nth-of-type(2)"

to

TAG POS=1 TYPE=I ATTR=CLASS:fa<SP>fa-4x<SP>cor-superior<SP>fa-desktop

and the pdf comes with original name, I believe selector is not the problem, in these new site for some reason the Var1 in filename dont work, nad I want learn how to discover (debug) the reason of that. Pls, can you give some tips?

Thanks
Hum, strange, it should work indeed... :o
Then..., pfff..., I don't really know..., try without a Space in your Var, and without the '+' and if you manage to use some hard-coded Var for the Filename, then you could first extract the original Filename with 'EXTRACT=HREF' or 'EXTRACT=HTM' and build yourself the final Name that you want using 'EVAL()' again... (=> without using the '+' Functionality...).
Last edited by chivracq on Thu Dec 27, 2018 2:51 am, edited 1 time in total.
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
Posts: 8525
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Choose pdf name dynamically by variable does not work, datetime only

Post by chivracq » Thu Dec 27, 2018 2:34 am

chivracq wrote:
Thu Dec 27, 2018 1:49 am
... and without the '+' and if you manage to use some hard-coded Var for the Filename, then you could first extract the original Filename with 'EXTRACT=HREF' or 'EXTRACT=HTM' and build yourself the final Name that you want using 'EVAL()' again... (=> without using the '+' Functionality...).
=> And yep indeed, that Principle works fine for me, applied for example to your first Site...:

Code: Select all

VERSION BUILD=8820413 RECORDER=FX
SET !EXTRACT_TEST_POPUP NO
TAB T=1
URL GOTO=https://www.wdl.org/pt/item/18529/

TAG POS=1 TYPE=H1 ATTR=ID:page-title EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var z=s.trim(); z;")

'TAG POS=1 TYPE=A ATTR=TXT:1.1<SP>MB<SP>18529.pdf
TAG POS=1 TYPE=A ATTR=TXT:*<SP>*.pdf EXTRACT=HREF
'=> Extracted: "https://dl.wdl.org/18529/service/18529.pdf"
SET !VAR2 EVAL("var s='{{!EXTRACT}}', v='{{!VAR1}}'; var x,y,z; x=s.lastIndexOf('/'); y=s.substr(x+1); z=y.replace('.pdf','_'+v+'.pdf'); z;")
PROMPT VAR1:<SP>_{{!VAR1}}_<BR>VAR2:<SP>_{{!VAR2}}_
'PAUSE

'TAG POS=1 TYPE=A ATTR=TXT:Downloads
ONDOWNLOAD FOLDER=* FILE={{!VAR2}} WAIT=YES
TAG POS=1 TYPE=A ATTR=TXT:*<SP>*.pdf
WAIT SECONDS=1
=> Some "18529_Valência. Mercado.pdf" File then gets downloaded into my Default iMacros 'Downloads' Folder...! :D

(Tested on iMacros for FF v8.8.2, Pale Moon v26.3.3 (=FF47), Win10_x64.)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
Posts: 8525
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Choose pdf name dynamically by variable does not work, datetime only

Post by chivracq » Fri Dec 28, 2018 4:10 am

And...., any Follow-up...? :?:

(You saw about 12h ago my last Reply with the Script I wrote for you about 24h ago, I guess you had the time to "test" it I would think... :wink: )
[I very-very rarely write Scripts for other Users, I did it twice for you already... => Try to follow up a mini-bit "quicker" maybe, would be nice... :wink: ]
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Program
Posts: 10
Joined: Wed Jan 10, 2018 4:05 pm

Re: Choose pdf name dynamically by variable does not work, datetime only

Post by Program » Thu Jan 03, 2019 6:19 pm

Dear chivracq, sorry due to the holidays of the end of the year, I came here, see answer but I had no way to test before, only today I tested.
In the wdl example site works perfectly, but on the site that I have tried that is a site that requires user and password, it is not working.

I thought that what would work in one should work in the other, but for some reason has not happened thus, I will try to pass as much information as possible, since it is a site that requires login with username and password.

I'll share here exactly the code I use on the site (this is a static example):

Code: Select all

SET !VAR1 Hello<SP>World
PROMPT _{{!VAR1}}_
ONDOWNLOAD FOLDER=* FILE={{!VAR1}}.pdf WAIT=YES
TAG POS=1 TYPE=I ATTR=CLASS:fa<SP>fa-4x
'TAG SELECTOR="#step5>A:nth-of-type(2)"
WAIT SECONDS=1
This static example above works in thie specific site, and after I try a more simple dynamic:

Code: Select all

TAG SELECTOR="#step2>DIV>H3>B" EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var z=s.trim(); z;")
PROMPT _{{!VAR1}}_
ONDOWNLOAD FOLDER=* FILE={{!VAR1}}.pdf WAIT=YES
TAG POS=1 TYPE=I ATTR=CLASS:fa<SP>fa-4x
WAIT SECONDS=1
The prompt bring me the "_Class<SP>1<SP>-<SP>Morphology<SP>00:11:31<SP>|<SP>cod:<SP>0_" ok, but the filename dont change to this, the filename come as the original name when downloaded without imacros: "12734.pdf"

testei novamente:

Code: Select all

TAG SELECTOR="#step2>DIV>H3>B" EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var z=s.trim(); z;")
PROMPT _{{!VAR1}}_
SET !VAR2 EVAL("var s='{{!EXTRACT}}', v='{{!VAR1}}'; var x,y,z; x=s.lastIndexOf('/'); y=s.substr(x+1); z=y.replace('.pdf','_'+v+'.pdf'); z;")
PROMPT VAR1:<SP>_{{!VAR1}}_<BR>VAR2:<SP>_{{!VAR2}}_
ONDOWNLOAD FOLDER=* FILE={{!VAR1}} WAIT=YES
TAG POS=1 TYPE=I ATTR=CLASS:fa<SP>fa-4x
WAIT SECONDS=1
The "PROMPT VAR1:<SP>_{{!VAR1}}_<BR>VAR2:<SP>_{{!VAR2}}_" brings me:
"VAR1: _Class 1 - Morphology 00:11:31 | cod: 0_ VAR2: _ Class 1 - Morphology 00:11:31 | cod: 0 _"

And again the filename dont change and come with original name.

If in static way works, I gues the dynamic must work too, and the extract and and filling in the variables is ok, as the prompt demonstrates,but for some reason the FILE command does not seem to recognize the variable in these specific site.

what is more intriguing is that it seems to me to be something very simple, because it is statically working, but at the same time, all the possibilities and variations I tried, none works.

If you have another suggestion, I will be very grateful, and I hope this my doubt helps other people.
thanks!
Last edited by Program on Fri Jan 04, 2019 2:33 am, edited 1 time in total.
chivracq
Posts: 8525
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Choose pdf name dynamically by variable does not work, datetime only

Post by chivracq » Thu Jan 03, 2019 9:29 pm

Program wrote:
Thu Jan 03, 2019 6:19 pm
Dear chivracq, sorry due to the holidays of the end of the year, I came here, see answer but I had no way to test before, only today I tested.
In the wdl example site works perfectly, but on the site that I have tried that is a site that requires user and password, it is not working.

I thought that what would work in one should work in the other, but for some reason has not happened thus, I will try to pass as much information as possible, since it is a site that requires login with username and password.

I'll share here exactly the code I use on the site (this is a static example):

Code: Select all

SET !VAR1 Hello<SP>World
PROMPT _{{!VAR1}}_
ONDOWNLOAD FOLDER=* FILE={{!VAR1}}.pdf WAIT=YES
TAG POS=1 TYPE=I ATTR=CLASS:fa<SP>fa-4x<SP>cor-superior<SP>fa-desktop&&TXT:
'TAG SELECTOR="#step5>A:nth-of-type(2)"
WAIT SECONDS=1
This static example above works in thie specific site, and after I try a more simple dynamic:

Code: Select all

TAG SELECTOR="#step2>DIV>H3>B" EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var z=s.trim(); z;")
PROMPT _{{!VAR1}}_
ONDOWNLOAD FOLDER=* FILE={{!VAR1}}.pdf WAIT=YES
TAG POS=1 TYPE=I ATTR=CLASS:fa<SP>fa-4x<SP>cor-superior<SP>fa-desktop&&TXT:
WAIT SECONDS=1
The prompt bring me the "_Aula 1 - Morfologia 00:31:36 | cod: 59198_" ok, but the filename dont change to this, the filename come as the original name when downloaded without imacros: "56754.pdf"

testei novamente:

Code: Select all

TAG SELECTOR="#step2>DIV>H3>B" EXTRACT=TXT
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var z=s.trim(); z;")
PROMPT _{{!VAR1}}_
SET !VAR2 EVAL("var s='{{!EXTRACT}}', v='{{!VAR1}}'; var x,y,z; x=s.lastIndexOf('/'); y=s.substr(x+1); z=y.replace('.pdf','_'+v+'.pdf'); z;")
PROMPT VAR1:<SP>_{{!VAR1}}_<BR>VAR2:<SP>_{{!VAR2}}_
ONDOWNLOAD FOLDER=* FILE={{!VAR1}} WAIT=YES
TAG POS=1 TYPE=I ATTR=CLASS:fa<SP>fa-4x<SP>cor-superior<SP>fa-desktop&&TXT:
WAIT SECONDS=1
The "PROMPT VAR1:<SP>_{{!VAR1}}_<BR>VAR2:<SP>_{{!VAR2}}_" brings me:
"VAR1: _Aula 1 - Morfologia 00:31:36 | cod: 59198_ VAR2: _ Aula 1 - Morfologia 00:31:36 | cod: 59198 _"

And again the filename dont change and come with original name.

If in static way works, I gues the dynamic must work too, and the extract and and filling in the variables is ok, as the prompt demonstrates,but for some reason the FILE command does not seem to recognize the variable in these specific site.

what is more intriguing is that it seems to me to be something very simple, because it is statically working, but at the same time, all the possibilities and variations I tried, none works.

If you have another suggestion, I will be very grateful, and I hope this my doubt helps other people.
thanks!
Yeah well, would be nice if you could follow up a little bit quicker though, I kind of have to "start again from the beginning" otherwise each time, and I don't keep all the Scripts I use to do some Testing for every Thread on the Forum...

But hum, you need to understand the "Principle" I applied/demonstrated in my last Script, the 'EVAL()' Statement I used for your '!VAR2' Var:

Code: Select all

SET !VAR2 EVAL("var s='{{!EXTRACT}}', v='{{!VAR1}}'; var x,y,z; x=s.lastIndexOf('/'); y=s.substr(x+1); z=y.replace('.pdf','_'+v+'.pdf'); z;")
... is meant to be applied on an 'EXTRACT=HREF' with returns the Path/URL of the File to download, and not on an 'EXTRACT=TXT' like you are doing... I mentioned each time as Comment what exactly gets extracted which is the "Starting Point" (or the original "Input") for the 'EVAL()'.

And yep, it will work for the exact specific Example I was able to use, but you then probably need to modify/adapt it to your next Site, depending on what will be different on that 2nd Site from the 1st Site... :idea:
But I tried to make my 'EVAL()' as generic and "universal" as possible, with for example the 'lastIndexOf('/')' which I would expect to work on any URL linking to some File to download... 8)
Last edited by chivracq on Fri Jan 04, 2019 2:35 am, edited 1 time in total.
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Program
Posts: 10
Joined: Wed Jan 10, 2018 4:05 pm

Re: Choose pdf name dynamically by variable does not work, datetime only

Post by Program » Fri Jan 04, 2019 2:31 am

Dear

I discover the problem, first my step by step, using the wdl as example, but fixing the value of variable var equal as have in my second site.

Code: Select all

SET !EXTRACT_TEST_POPUP NO
TAB T=1
URL GOTO=https://www.wdl.org/pt/item/18529/

'TAG POS=1 TYPE=H1 ATTR=ID:page-title EXTRACT=TXT
'SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var z=s.trim(); z;")

SET !VAR1 Class<SP>1<SP>-<SP>Morphology<SP>00:11:31<SP>|<SP>cod:<SP>0
PROMPT _{{!VAR1}}_
'TAG POS=1 TYPE=A ATTR=TXT:1.1<SP>MB<SP>18529.pdf
TAG POS=1 TYPE=A ATTR=TXT:*<SP>*.pdf EXTRACT=HREF
PROMPT _{{!EXTRACT}}_
'=> Extracted: "https://dl.wdl.org/18529/service/18529.pdf"
SET !VAR2 EVAL("var s='{{!EXTRACT}}', v='{{!VAR1}}'; var x,y,z; x=s.lastIndexOf('/'); y=s.substr(x+1); z=y.replace('.pdf','_'+v+'.pdf'); z;")
PROMPT _{{!VAR2}}_
PROMPT VAR1:<SP>_{{!VAR1}}_<BR>VAR2:<SP>_{{!VAR2}}_
'PAUSE

'TAG POS=1 TYPE=A ATTR=TXT:Downloads
ONDOWNLOAD FOLDER=* FILE={{!VAR2}} WAIT=YES
TAG POS=1 TYPE=A ATTR=TXT:*<SP>*.pdf
WAIT SECONDS=1
So I see that imacros recognize ":" with purle color, I and then I discovered the riddle and removed all these different symbols of letters and work, so I do a new script:

Code: Select all

...
SET !VAR1 Class<SP>1<SP>-<SP>Morphology<SP>00:11:31<SP>|<SP>cod:<SP>0
PROMPT _{{!VAR1}}_
SET !VAR1 EVAL("var s=\"{{!VAR1}}\"; s.split(\" 00:\", 1);")
...
So anyone with the same problem can do with same step by step as I do, I recommend alwayts split all characters other than letters and numbers.
chivracq
Posts: 8525
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Choose pdf name dynamically by variable does not work, datetime only

Post by chivracq » Fri Jan 04, 2019 2:52 am

Program wrote:
Fri Jan 04, 2019 2:31 am
Dear

I discover the problem, first my step by step, using the wdl as example, but fixing the value of variable var equal as have in my second site.

Code: Select all

SET !EXTRACT_TEST_POPUP NO
TAB T=1
URL GOTO=https://www.wdl.org/pt/item/18529/

'TAG POS=1 TYPE=H1 ATTR=ID:page-title EXTRACT=TXT
'SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var z=s.trim(); z;")

SET !VAR1 Class<SP>1<SP>-<SP>Morphology<SP>00:11:31<SP>|<SP>cod:<SP>0
PROMPT _{{!VAR1}}_
'TAG POS=1 TYPE=A ATTR=TXT:1.1<SP>MB<SP>18529.pdf
TAG POS=1 TYPE=A ATTR=TXT:*<SP>*.pdf EXTRACT=HREF
PROMPT _{{!EXTRACT}}_
'=> Extracted: "https://dl.wdl.org/18529/service/18529.pdf"
SET !VAR2 EVAL("var s='{{!EXTRACT}}', v='{{!VAR1}}'; var x,y,z; x=s.lastIndexOf('/'); y=s.substr(x+1); z=y.replace('.pdf','_'+v+'.pdf'); z;")
PROMPT _{{!VAR2}}_
PROMPT VAR1:<SP>_{{!VAR1}}_<BR>VAR2:<SP>_{{!VAR2}}_
'PAUSE

'TAG POS=1 TYPE=A ATTR=TXT:Downloads
ONDOWNLOAD FOLDER=* FILE={{!VAR2}} WAIT=YES
TAG POS=1 TYPE=A ATTR=TXT:*<SP>*.pdf
WAIT SECONDS=1
So I see that imacros recognize ":" with purle color, I and then I discovered the riddle and removed all these different symbols of letters and work, so I do a new script:

Code: Select all

...
SET !VAR1 Class<SP>1<SP>-<SP>Morphology<SP>00:11:31<SP>|<SP>cod:<SP>0
PROMPT _{{!VAR1}}_
SET !VAR1 EVAL("var s=\"{{!VAR1}}\"; s.split(\" 00:\", 1);")
...
So anyone with the same problem can do with same step by step as I do, I recommend alwayts split all characters other than letters and numbers.
Alright, very good, and Thanks for sharing your Final Script, and I guess you understood the "Principle" and will be able to reuse it in other Cases... :D

Hum, and "funny", I don't think I "knew" this Syntax "s.split(' 00:', 1)" you are using for 'split()' that apparently can accept 2 Parameters and I guess your Syntax gives the same Result like the one I use: "s.split(' 00:')[1]", which could be "interesting" for me, as iMacros (at least the v8.8.2 + v8.9.7 Versions I use on PM and FF) doesn't "like it at all" when there is no 2nd part for the 'split()', solved by using '!ERRORIGNORE', except in v10.0.2 for FF where the Script then hangs if the 'EVAL()' is being executed after some Network/Connection Error. I'll have to try your Syntax to see if maybe it works "better" in some specific Cases where "mine" fails, ah-ah...! :wink:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
Post Reply