httpRequest on google

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
optoron
Newbie
Posts: 11
Joined: Sun Jan 31, 2010 2:08 pm

httpRequest on google

Post by optoron » Tue Feb 15, 2011 1:13 am

hi, i am trying to do a httprequest on google translate, but have failed miserably so far..
since i'm terrible with using vb, i didn't get very far.

Code: Select all

let>txt=カテゴリー

let>post_re=translate_t?hl=en&ie=UTF8&text=%txt%&langpair=ja|en
HTTPRequest>http://translate.google.com/,d:\trans.txt,POST,post_re,reply
it worked fine when the http is typed into the address bar and sent, but with the httprequest, the return contains no translation. i think it is bcos google is using a textbox for the translating word, and i have no idea how to get round it.

any help will be most appreciate.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Tue Feb 15, 2011 4:15 am

Try this.
Be sure to read the section of Macro Scheduler on how to enable SSL support because this is using a URL of https

Code: Select all

let>txt=hello

//Get your own Google_api_key here:
//https://code.google.com/apis/console/
Let>Google_api_key=AIasdasdkULliuliNINIIIadasd2
HTTPRequest>https://www.googleapis.com/language/translate/v2?key=%Google_api_key%&q=%txt%&source=en&target=fr&callback=handleResponse,,GET,,reply

MessageModal>reply

optoron
Newbie
Posts: 11
Joined: Sun Jan 31, 2010 2:08 pm

Post by optoron » Tue Feb 15, 2011 5:20 am

this is pretty cool. thanks adroege for pointing me in the right direction as i never knew about the api requirements.
the problem is now that it doesn't handle the japanese characters correctly, but i may have an idea on how to deal with it..

extremely grateful for your help.. cheers!!

optoron
Newbie
Posts: 11
Joined: Sun Jan 31, 2010 2:08 pm

Post by optoron » Wed Feb 16, 2011 4:13 pm

hi again...
sorry for being a pain. any idea how i can do a similar job with
http://www.excite.co.jp/world/english/
i'm pretty much stump with as i am not getting any results.

Code: Select all

let>h1=http://www.excite.co.jp/world/english/
let>h2=
let>h3=post
let>h4=?before=hello&wb_lp=ENJA&after=handleResponse

HTTPRequest>%h1%,%h2%,%h3%,%h4%,reply

msg>reply
i know it's possible as i seen varous code handling the request, but it's just not working for me..

i'll be extremely grateful for any help.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Wed Feb 16, 2011 7:06 pm

Well when I ran your code nothing appeared to happen because the message box popped up BEHIND the main window.

Changing this to a MessageModal> solved this problem.


Then I was able to see a great deal of HTML returned.


So can you clarify your problem?

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Wed Feb 16, 2011 7:24 pm

This may help you - it's an example I built a long time ago.
--------------------

Here is a simple example built with version 10 of Macro Scheduler.

Version 12 has MUCH greater control over Dialogs and so you have many more creative options with that version. Version 12 should run this code also since it is backward compatible.

Run it, then fill in a zipcode and click the go button.

Code: Select all

// Show the results of a parsed webpage inside a Dialog

Dialog>Dialog1
   Caption=Dialog1
   Width=403
   Height=301
   Top=150
   Left=31
   Edit=msEdit1,80,40,81,
   Label=ZipCode,24,40,true
   Button=Go,232,40,75,25,3
   Memo=msMemo1,40,96,273,113,
   Label=Get Weather Info,64,8,true
EndDialog>Dialog1


Show>Dialog1

Label>MainLoop
   GetDialogAction>Dialog1,result
   If>result=2,End
   If>result=3,GetWeather
   Wait>0.01
Goto>MainLoop

SRT>GetWeather
   Let>zip_code=Dialog1.msEdit1
   Let>URL=http://www.briansutton.com/wx/weather.html?id=%zip_code%&length=10&unit=s&#current
   HTTPRequest>URL,,GET,,HTMLResponse

   Let>String1=<td width="41%" height="24" align="center" valign="top">
   Let>String2=</td>

   Length>String1,String1_length

   Position>String1,HTMLResponse,1,StartAt
   Add>StartAt,String1_length
   Position>String2,HTMLResponse,StartAt,EndAt,FALSE

   Let>myLen=EndAt-StartAt

   MidSTr>HTMLResponse,StartAt,myLen,myWeather
   Let>Dialog1.msMemo1=The current weather for zipcode %zip_code% is %CRLF%%CRLF%%myWeather%
   ResetDialogAction>Dialog1
END>GetWeather

Label>End


optoron
Newbie
Posts: 11
Joined: Sun Jan 31, 2010 2:08 pm

Post by optoron » Thu Feb 17, 2011 3:12 am

apologies as i did not state my problem clearly.
i'm trying to build a japanese translator using various online website. eg. google, excite, babel etc,
and i thought it may be possible with httprequest as found other various code handling it.
when i try using the httprequest, it does not contain any translation within the return page..

if you save the httprequest return as html, you can see the as if browser returns.
meaning browsing without internet exploer, am i correct?
but i just can't get it to work in my project. it display pages minus the translation.

thanks to you, i got google to work, but for others, i'm at total lost.

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Thu Feb 17, 2011 12:36 pm

This works for me. It translates from English to French

To not have to view the results in a browser (like I did here)
you would have to parse the answer out of the HTML and view just
the result.

Code: Select all

Let>txt=hello
Let>url=http://babelfish.yahoo.com/translate_txt?ei=UTF-8&doit=done&fr=bf-res&intl=1&tt=urltext&trtext=%txt%&lp=en_fr&btnTrTxt=Translate
HTTPRequest>url,c:\reply.htm,GET,,reply

ExecuteFile>c:\reply.htm
//MessageModal>reply

optoron
Newbie
Posts: 11
Joined: Sun Jan 31, 2010 2:08 pm

Post by optoron » Thu Feb 17, 2011 6:13 pm

YESSSSS!! that is what i wanted!!!! how did you do it?? when you do a translation , the address bar do not show you the the syntax for the fetching of the translation. so i do not understand how you managed to find what to send in the http request..

can you pls tell me how did you manage to find the correct html syntax for the http request?? i have been trying to find the correct way to get this result by parsing the html source page and from othe various sources, but have no luck getting any result.. i even seen source code, but cannot get this desire results from macro scheduler..

i would be ever grateful if you can explain/point to me where i can get more info to produce this kind of result as i have other websites which i like to use for my project.

thank you very much for your help!

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Post by adroege » Thu Feb 17, 2011 6:45 pm

I use FireFox browser. Install the Add-on called "Web Developer" I installed the latest version "Web Developer 1.1.9

Then when you have a web page showing on screen, there are many things the "Web Developer Add-on" can do for you. What I did is select an option which dynamically changes form methods from POST to GET. Then when you fill in the parameters and click the submit button, the URL will show you the correct parameter string. And also many web sites which originally coded POST into their form will ALSO accept it as a GET request. This is what I did with the translate example.

optoron
Newbie
Posts: 11
Joined: Sun Jan 31, 2010 2:08 pm

Post by optoron » Fri Feb 18, 2011 4:50 am

Thank You and you ROCKS!!
for showing me this very interesting piece of tool you found there..
it let me explores the alot of the hidden parameters when sourcing the webpages.

Unfortunately, for me, some of the translating website do not fully works yet and
some that works but return pages giving me a '' translation,
especially when the return have japanese characters.
i think i know why, but have not found any immediate answer yet.
i will further my experiment with this wonderful tool you shown me.

lots of kudos to you.. but unfortunately, the forum will not let me rep you again.. sorry.. :cry: :cry:

you have given me hope for this little project of mine and so many many thanks to you!

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts