Sign in to follow this  
Followers 0
Zeeshaan

Get info from online Dictionary

18 posts in this topic

Greetings,

i am trying to put and get information from a web page.

but i don't want website to be showed in my program.

this is the link: http://www.hamariweb.com/dictionaries/urdu-english-dictionary.aspx

you can see it's an online dictionary where we can put English words and get output results as translation.

This is the frame which i have to use:

when we enter a world in the form and click search. we get meanings of words.

All i want to do is make a GUI and use this frame there.

i am new to AutoIt. So, how can i start doing it?

Any Example to show me the right path would be great and really appreciated.

Thanks!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

This is an example:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.6.1
 Author:         RMR

 Script Function:
    English to Urdu Translator.

#ce ----------------------------------------------------------------------------

#include <String.au3>
#include <INet.au3>

$EngWord = InputBox("Dictionary", "Enter any english word:")
$source = _INetGetSource('http://www.hamariweb.com/dictionaries/urdu-english-dictionary.aspx?eu=' & $EngWord)
MsgBox(0, "Translated from english to URDU", StringStripWS(StringRegExpReplace($source, '(?i)(?s).*?<td width="33%" style="color:blue;FONT-WEIGHT:bold;FONT-SIZE:10pt;FONT-FAMILY:verdana;BORDER-BOTTOM:#8278A3 1px solid;BORDER-COLLAPSE:collapse">(.*?)</td>.*$', "\1"),3))
Edited by RMR

Share this post


Link to post
Share on other sites

Thanks RMR, but i want to get this Frame:

how to extract only this from the whole website source?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

like this

#include <GUIConstantsEx.au3>
#include <INet.au3>
Global $file, $btn, $msg
    
GUICreate(" My GUI input acceptfile", 320, 120, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45 )
$file = GUICtrlCreateInput("", 10, 5, 300, 20)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
$btn = GUICtrlCreateButton("Translate", 40, 75, 60, 20)
GUISetState()

While $msg <> $GUI_EVENT_CLOSE
    $msg = GUIGetMsg()
    Select
        Case $msg = $btn
            $_Query =GUICtrlRead ( $file ) 
            If $_Query <> '' Then _Tranlate ( $_Query )
    EndSelect
WEnd

Func _Tranlate ( $_FQuery )
    GUICtrlSetState ( $btn, $GUI_DISABLE ) 
    $source = _INetGetSource('http://www.hamariweb.com/dictionaries/urdu-english-dictionary.aspx?eu=' & $_FQuery )
    MsgBox(0, "Translated from english to URDU", StringStripWS ( StringRegExpReplace($source, '(?i)(?s).*?<td width="33%" style="color:blue;FONT-WEIGHT:bold;FONT-SIZE:10pt;FONT-FAMILY:verdana;BORDER-BOTTOM:#8278A3 1px solid;BORDER-COLLAPSE:collapse">(.*?)</td>.*, "\1"), 7 ))
    GUICtrlSetState ( $btn, $GUI_ENABLE ) 
EndFunc

sorry i don't see your last post...Posted Image

Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Zeeshan,

Why not you design a new GUI using Koda instead of extracting from that site?

Share this post


Link to post
Share on other sites

ok, if we can not extract the form from website then i am ready to design my own GUI.

but the only problem is that the scripts you guys provided show only English Results.

Urdu translation is not showed.

Also, there are too many spaces in result.

can you help me to get both English and Urdu Results? Also removing the extra spaces?

Share this post


Link to post
Share on other sites

ok, if we can not extract the form from website then i am ready to design my own GUI.

but the only problem is that the scripts you guys provided show only English Results.

Urdu translation is not showed.

Also, there are too many spaces in result.

can you help me to get both English and Urdu Results? Also removing the extra spaces?

Use StringStripWS ( ) function


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

but i am not getting the Urdu (Arabic Type) Results as output.

i am only getting Roman English results as translation.

when we type some word, for example "Human" the 2 translations are provided.

1- English to Roman (looks like English but different)

2- Urdu (Looks like Arabic)

but i am only getting 1st result.

how to get both?

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Zeeshan,

Try this ;)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <INet.au3>

$Dic = GUICreate("English to Urdu Dictionary - Online", 317, 242, 261, 136)
$Label1 = GUICtrlCreateLabel("Enter a word and click translate button to translate in Urdu", 8, 8, 294, 17)
GUICtrlSetFont(-1, 9, 400, 0, "MS Sans Serif")
$Word = GUICtrlCreateInput("", 8, 32, 300, 21)
$Roman = GUICtrlCreateInput("", 8, 80, 300, 42)
GUICtrlSetState(-1, $GUI_DISABLE)
$Arabic = GUICtrlCreateInput("", 8, 144, 300, 42)
GUICtrlSetState(-1, $GUI_DISABLE)
$RomanL = GUICtrlCreateLabel("Roman Urdu", 8, 59, 64, 17)
$ArabicL = GUICtrlCreateLabel("Arabic Urdu", 10, 125, 60, 17)
$Translate = GUICtrlCreateButton("Translate", 8, 190, 300, 45, $WS_GROUP)
GUICtrlSetFont(-1, 9, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $Translate
            $_Query = GUICtrlRead($Word)
            If $_Query <> '' Then _Tranlate($_Query)
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func _Tranlate($_FQuery)
    GUICtrlSetState($Translate, $GUI_DISABLE)
    GUICtrlSetData($Roman, "")
    GUICtrlSetState($Roman, $GUI_DISABLE)
    GUICtrlSetData($Arabic, "")
    GUICtrlSetState($Arabic, $GUI_DISABLE)
    GUICtrlSetData($Translate, "Translating...")
    $source = _INetGetSource('http://www.hamariweb.com/dictionaries/urdu-english-dictionary.aspx?eu=' & $_FQuery)
    If StringRegExp($source, "No Results found,") Then
        GUICtrlSetData($Roman, "No Results Found!")
        GUICtrlSetData($Arabic, "No Results Found!")
    Else
        GUICtrlSetData($Roman, StringStripWS(StringRegExpReplace($source, '(?i)(?s).*?<td width="33%" style="color:blue;FONT-WEIGHT:bold;FONT-SIZE:10pt;FONT-FAMILY:verdana;BORDER-BOTTOM:#8278A3 1px solid;BORDER-COLLAPSE:collapse">(.*?)</td>.*$', "\1"), 3))
        GUICtrlSetData($Arabic, StringStripWS(StringRegExpReplace($source, '(?i)(?s).*?<td width="33%" align="right" style="color:blue;FONT-WEIGHT:bold;FONT-SIZE:12pt;FONT-FAMILY:verdana;BORDER-BOTTOM:#8278A3 1px solid;BORDER-COLLAPSE:collapse">(.*?)</td>.*$', "\1"), 3))
    EndIf
    GUICtrlSetState($Roman, $GUI_ENABLE)
    GUICtrlSetState($Arabic, $GUI_ENABLE)
    GUICtrlSetData($Translate, "Translate")
    GUICtrlSetState($Translate, $GUI_ENABLE)
EndFunc   ;==>_Tranlate

Edit: Corrected :)

Edited by RMR

Share this post


Link to post
Share on other sites

@ RMR

Correct your code. Tidy it and use Autoit Code Tags.

Share this post


Link to post
Share on other sites

Well done RMR !

Some characters are strange : Ù…Ø³Ø§Ù„Û Ù„Ú¯ÛŒ لاش Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Wakillon,

Its because your computer has no UDRU fonts installed ;)

Share this post


Link to post
Share on other sites

Wakillon,

Its because your computer has no UDRU fonts installed ;)

I ask that because when i try english to french it doesn't work !


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

1- it's not getting closed.

2- script gets freeze if there is no internet connectivity!

3- processes very slow...

Share this post


Link to post
Share on other sites

All you need for this is internet connectivity then you will not see any of this problem ;)

Share this post


Link to post
Share on other sites

i don't need that, i just tested it.

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

1- it's not getting closed.

2- script gets freeze if there is no internet connectivity!

3- processes very slow...

1. Only while the InetRead is active. A timeout would be nice.

2. Same as 1.

3. Wait what? From retrieving the information to displaying it on screen takes ~5 ms for me. The only slow part about the code is the InetRead, which is not even because the function is slow, but the connection to the website is. Now if someone could write a script to speed up the internet.... ;)

Edit:

This modification will keep the UI responsive during the download and would allow a cancel button to be implemented (I didn't yet), but it does make a temp file because it uses INetGet.

As a strange side effect this version does show the arabic letters for me, while the other version did not.

Pretty much just changed RMR's script to use GuiEventMode.

Opt("GuiOnEventMode",1)
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <INet.au3>
Global $CtrlInputWord, $CtrlInputRoman, $CtrlInputArabic
Global $bTranslate = False
Local $sWord

GUICreate("English to Urdu Dictionary - Online", 317, 242, 261, 136)
GUISetOnEvent(-3,"_Exit")
GUICtrlCreateLabel("Enter a word and click translate button to translate in Urdu", 8, 8, 294, 17)
GUICtrlSetFont(-1, 9, 400, 0, "MS Sans Serif")
$CtrlInputWord = GUICtrlCreateInput("", 8, 32, 300, 21)
GUICtrlSetOnEvent(-1,"_TriggerTranslate")
$CtrlInputRoman = GUICtrlCreateInput("", 8, 80, 300, 42)
GUICtrlSetState(-1, $GUI_DISABLE)
$CtrlInputArabic = GUICtrlCreateInput("", 8, 144, 300, 42)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateLabel("Roman Urdu", 8, 59, 64, 17)
GUICtrlCreateLabel("Arabic Urdu", 10, 125, 60, 17)
$CtrlButtonTranslate = GUICtrlCreateButton("Translate", 8, 190, 300, 45, $WS_GROUP)
GUICtrlSetOnEvent(-1,"_TriggerTranslate")
GUICtrlSetFont(-1, 9, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)

While 1
    If $bTranslate Then
        $sWord = GUICtrlRead($CtrlInputWord)
        If $sWord Then _Tranlate($sWord)
        $bTranslate = False
    EndIf
WEnd

Func _TriggerTranslate()
    $bTranslate = True
EndFunc

Func _Exit()
    Exit
EndFunc

Func _Tranlate($_FQuery)
    Local $sTempPath = @TempDir & "\translatesourcefile"
    GUICtrlSetState($CtrlButtonTranslate, $GUI_DISABLE)
    GUICtrlSetData($CtrlInputRoman, "")
    GUICtrlSetState($CtrlInputRoman, $GUI_DISABLE)
    GUICtrlSetData($CtrlInputArabic, "")
    GUICtrlSetState($CtrlInputArabic, $GUI_DISABLE)
    GUICtrlSetData($CtrlButtonTranslate, "Translating...")
    Local $hDownload = INetGet('http://www.hamariweb.com/dictionaries/urdu-english-dictionary.aspx?eu=' & $_FQuery,$sTempPath,0,1)
    Do
        Sleep(10)
    Until InetGetInfo($hDownload,2)
    $sSource = FileRead($sTempPath)
    FileDelete($sTempPath)
    If StringRegExp($sSource, "No Results found,") Then
    GUICtrlSetData($CtrlInputRoman, "No Results Found!")
    GUICtrlSetData($CtrlInputArabic, "No Results Found!")
    Else
    GUICtrlSetData($CtrlInputRoman, StringStripWS(StringRegExpReplace($sSource, '(?i)(?s).*?<td width="33%" style="color:blue;FONT-WEIGHT:bold;FONT-SIZE:10pt;FONT-FAMILY:verdana;BORDER-BOTTOM:#8278A3 1px solid;BORDER-COLLAPSE:collapse">(.*?)</td>.*$', "\1"), 3))
    GUICtrlSetData($CtrlInputArabic, StringStripWS(StringRegExpReplace($sSource, '(?i)(?s).*?<td width="33%" align="right" style="color:blue;FONT-WEIGHT:bold;FONT-SIZE:12pt;FONT-FAMILY:verdana;BORDER-BOTTOM:#8278A3 1px solid;BORDER-COLLAPSE:collapse">(.*?)</td>.*$', "\1"), 3))
    EndIf
    GUICtrlSetState($CtrlInputRoman, $GUI_ENABLE)
    GUICtrlSetState($CtrlInputArabic, $GUI_ENABLE)
    GUICtrlSetData($CtrlButtonTranslate, "Translate")
    GUICtrlSetState($CtrlButtonTranslate, $GUI_ENABLE)
EndFunc ;==>_Tranlate
Edited by Tvern

Share this post


Link to post
Share on other sites

Hi.

can anyone suggest how to embed that dictionary on a website.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0