Source language: Translate to:

problem with BrowserSetElement

General questions about NeoBook

Moderator: Neosoft Support

Re: problem with BrowserSetElement

Postby Tony Kroos » Wed Mar 30, 2016 2:20 pm

Let me see the text you're trying to translate. Looks like it has some special chars that confusing the script.
Also you may try this:
Code: Select all
BrowserExecScript "WebBrowser1" "var node = document.getElementById('result_box');|window.external.nbSetVar('Google',node.textContent)" "JScript"


Both scripts tested and worked fine at that moment with plain text.
Tony Kroos
 
Posts: 402
Joined: Thu Oct 15, 2009 3:43 pm

Re: problem with BrowserSetElement

Postby Wrangler » Thu Mar 31, 2016 10:46 am

Thanks Tony. I'll give it a go this weekend when I get back to the console.

I'd like to see someone capable turn this into a plugin. Al Meyer had one that worked really well, but Google upped their API and Al never updated.
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1507
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Re: problem with BrowserSetElement

Postby Wrangler » Thu Mar 31, 2016 11:22 am

Tony,

Forgot I had a copy of Neobook on my laptop. Tried your code and it works fine! I noticed that Google translate retains the carriage returns in the translation results, but your code doesn't. Is there anything we can add that will retain CR's in the output?

Thanks much for your help.
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1507
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Re: problem with BrowserSetElement

Postby Wrangler » Fri Apr 01, 2016 2:38 pm

Can anyone help with this code in getting it to retain carriage returns?

Code: Select all
BrowserExecScript "WebBrowser1" "var node = document.getElementById('result_box');|window.external.nbSetVar('Google',node.textContent)" "JScript"


I'm not real familiar with javascript.

Thanks
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1507
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Re: problem with BrowserSetElement

Postby Gaev » Fri Apr 01, 2016 4:04 pm

Wrangler:

I noticed that Google translate retains the carriage returns in the translation results, but your code doesn't. Is there anything we can add that will retain CR's in the output?

BrowserExecScript "WebBrowser1" "var node = document.getElementById('result_box');|window.external.nbSetVar('Google',node.textContent)" "JScript"

Am I right in assuming that the NeoBook variable [Google] does not separate (show) "new lines" properly ?

This could be because the line separator character in non-windows systems is ascii 13 ... and in windows systems, you need two characters ... ascii 13 followed by ascii 10 ... without the second character, windows programs will not advance to a new line e.g. when you view such text in notepad.exe, you might find dark black rectangles in place of ascii 13.

See this stackoverflow page for detailed explanation.

Can anyone help with this code in getting it to retain carriage returns?

You could replace the ascii 13 with the ascii 13 plus ascii 10 combo ... in javascript these values can be referenced as \r and \n ... but it might be easier to do this on the Neobook side e.g. ...
Code: Select all
StrReplace "[Google]" "[#13]" "[#13][#10]" "[newGoogle]" ""

... and see if [newGoogle] is properly formatted.

If not, do a FileWrite of [Google] to a .txt file ... and provide a link to where it can be downloaded.
User avatar
Gaev
 
Posts: 3735
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: problem with BrowserSetElement

Postby Wrangler » Fri Apr 01, 2016 4:36 pm

Thanks for the help, Gaev.

Yes. The [google] variable isn't showing new lines.

The strReplace didn't work. No special characters found in text file. It seems the characters are being stripped before populating the [google] variable. Example: "75-80 días.Cosecha". There should be a new paragraph after "días." that begins with "Cosecha". The google translate box that this data is grabbed from correctly shows the paragraphs. I thought maybe this could be done within the javascript itself before it's sent to the [google] variable.
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1507
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Re: problem with BrowserSetElement

Postby Gaev » Fri Apr 01, 2016 5:40 pm

Wrangler:

The google translate box that this data is grabbed from correctly shows the paragraphs. I thought maybe this could be done within the javascript itself before it's sent to the [google] variable.

Did some more experiments ... the culprit is .textContent ... I tried it against content that was defined as
Code: Select all
firstLine<br/>secondLine
... and then did a javascript alert on the result ... the result was shown as firstLinesecondLine.

Try using innerHTML instead ...
Code: Select all
BrowserExecScript "WebBrowser1" "var node = document.getElementById('result_box');|window.external.nbSetVar('Google',node.innerHTML)" "JScript"

You should see <br/> or some other html tag between the two lines in your NeoBook variable [Google] ... if so, it should be easy to replace it with [#13][#10].

Fingers crossed.

P.S. Also, note that "The textContent property is not supported in Internet Explorer 8 and earlier."
User avatar
Gaev
 
Posts: 3735
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: problem with BrowserSetElement

Postby Wrangler » Fri Apr 01, 2016 6:58 pm

That did the trick. :) Got <BR> for carriage returns along with a whole crapload of <span> </span>. Easy to strReplace. Here's the code for anyone else who may need it:

Code: Select all
setvar "[delay]" "1000"

BrowserGoTo "WebBrowser5" "https://translate.google.com"
delay "[delay]"
setvar "[clipboard]" "[strains-spanish.strains.straindesc]"
FocusObject "WebBrowser5"
delay "[delay]"
SendKeys "" "{CtrlDn}v{CtrlUp}"
delay "[delay]"

BrowserExecScript "WebBrowser5" "var node = document.getElementById('result_box');|window.external.nbSetVar('Google',node.innerHTML)" "JScript"
delay "[delay]"
StrReplace "[Google]" "<span>" "" "[newGoogle]" ""
StrReplace "[newGoogle]" "</span>" "" "[newGoogle]" ""
StrReplace "[newGoogle]" "<BR>" "[#13]" "[newGoogle]" ""
alertbox "" "[newgoogle]"


A little clunky using the clipboard, but it works. The clipboard part could probably be eliminated using jscript as well. The delay can be adjusted according to your network connection by changing the [delay] variable.

Thank you, Gaev!
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1507
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Previous

Return to General NeoBook Discussions

Who is online

Users browsing this forum: No registered users and 4 guests

cron