Sign in to follow this  
Followers 0
_Kurt

Inet Source Problem..

7 posts in this topic

Hey guys,

I've tried to study some scripts but I'm not quite getting there. How can you make it so you can "click" a button on a site and return something? Let's use an example translator script found in Scripts and Scraps.

#include <GuiConstants.au3>
#Include <Misc.au3>
;#NoTrayIcon
Opt("GUIOnEventMode", 1)

TranslateInit()
While 1
    Sleep(100)
WEnd


Func TranslateInit()
    Global $oHTTP
    HotKeySet("{F2}", "TranslateStart")
    $oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
EndFunc

Func TranslateStart()
    ToolTip("Translating", 0, 0)
    Send("^c")
    $Text = ClipGet()
    $Translation = _Translate($Text, "en", "fr")
    $Translation = Web2Text($Translation)
    ClipPut($Translation)
    guiTranslationText($Text, $Translation)
EndFunc

Func Web2Text($Text)
    $Text = StringReplace($Text, "." & @CRLF, "." & @CR)
    $Text = StringReplace($Text, @CR & @CRLF, @CR & @CR)
    $Text = StringReplace($Text, @CRLF, " ")
    $Text = StringReplace($Text, @CR, @CRLF)
    Return $Text
EndFunc

Func guiTranslationText($Original, $Translated)
    GuiCreate("Translation Service", 805, 425,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))
    GUISetOnEvent($GUI_EVENT_CLOSE, "TranslationTextClose")
    GuiCtrlCreateEdit($Original, 10, 10, 780, 190, $ES_MULTILINE)
    GuiCtrlCreateEdit($Translated, 10, 210, 780, 200, $ES_MULTILINE)
    GuiSetState()
EndFunc

Func TranslationTextClose()
    GUIDelete(@GUI_WinHandle)
EndFunc

Func String2WWW($Text)
    $Text = StringReplace($Text, "&", "&amp;")
    $Text = StringReplace($Text, " ", "+")
    $Text = StringReplace($Text, "à", "&agrave;")
    $Text = StringReplace($Text, "é", "&eacute;")
    $Text = StringReplace($Text, "ï", "&iuml;")
    $Text = StringReplace($Text, "ô", "&ocirc;")
    $Text = StringReplace($Text, "ç", "&ccedil;")
    $Text = StringReplace($Text, "À", "&Agrave;")
    $Text = StringReplace($Text, "É", "&Eacute;")
    $Text = StringReplace($Text, "©", "&copy;")
    $Text = StringReplace($Text, "<", "&lt;")
    $Text = StringReplace($Text, ">", "&gt;")
    ;$Text = StringReplace($Text, @CRLF, "%0D%0A")
    ;$Text = StringReplace($Text, '"', "%22")
    $string = ""
    For $i=1 To StringLen($text)
        $char = StringMid($Text, $i, 1)
        If $char <> "+" And $char <> "&"  And $char <> ";" And StringIsAlNum($char)<>1 Then $char = "%" & Hex(Asc($char),2)
        $string = $string & $char
    Next
    Return $string
EndFunc

Func _Translate($Text, $From, $To)
    $Text = String2WWW($Text)
    $oHTTP.Open("GET","http://babelfish.altavista.digital.com/tr?doit=done&intl=1&tt=urltext&trtext=" & $Text & "&lp=" & $From & "_" & $To & "&btnTrTxt=Translate")
    $oHTTP.Send()
    $HTMLSource = $oHTTP.Responsetext
    ToolTip("Done", 0, 0) 
    Sleep(10)
    ToolTip("")
    $Text = _StringBetween($HTMLSource, "<div style=padding:10px;>", "</div>")
    $Text = StringReplace($Text, @LF, @CRLF)
    Return $Text
EndFunc

Func _StringBetween($s, $from, $to)
    $x = StringInStr($s, $from) + StringLen($from)
    $y = StringInStr(StringTrimLeft($s, $x), $to)
    Return StringMid($s, $x, $y)
EndFunc

1) Which lines are the ones that "change the input box on the site and click the button"

2) I've also looked over the sites source code, I'm not finding which lines are used for this script, any reason why?

Thanks,

Kurt


Awaiting Diablo III..

Share this post


Link to post
Share on other sites



Well IE Automation can click a button for you, but I'm not sure what you mean by "return something"...return what exactly? The source of the page after clicking the button? The web location? The browser state? "Return Something: could mean dozens of things, you'll have to be more specific.


The cake is a lie.www.theguy0000.com is currentlyUP images.theguy0000.com is currentlyUP all other *.theguy0000.com sites are DOWN

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I still do not understand how to type in something in an input box (on a site) or click a button for the user. I'm not a fast learner as you can see, and I have no experience in HTML. If you are nice enough to help me, I will appreciate it very much. Here's the part of the source code:

</td>

  <td width="33%" valign="top" align="center">
    <form method="GET" action="http://www.a2zwordfinder.com/cgi-bin/wordfinder.cgi" name="Anagram">
    <a href="anagram.html" target="_top"><font Face="Arial"><strong>Anagram WordFinder</strong></font><br>
    <img src="images/anagram.jpg" alt="" width="83" height="82" border="0"></a><br>
    <font Face="Arial"><strong><u>Example</u></strong><br>Build Words From 'EEHST'</font><br>
    <input type=hidden name="SearchType" value="Anagram">
    <input type=hidden name="MinLetters" value="2">
    <input type=hidden name="SortBy" value="Length">
    Letters: <input type=text name="Letters" value="eehst" size="5"><br>
    <input type="submit" value="Find Words" name="Search"><br>
    (<a href="http://www.gamesville.lycos.com/games/wordWrangler?FOD=1" target="_blank">Word Wrangler Pays Prizes...</a>)
    </form>
  </td>

The button displayed on the site is "Find Words" and the input default is "eehst". So the program basically is an input in a GUI and if the user types something in and presses the button, the prog takes the words from the input box and puts it in automatically in the site and clicks the button. Sorry if i took lots of your time explaning. If someone could write a small example I'd love that, but if that's too much to ask, just post in some functions to use/how to use them.

Thanks again,

Kurt

Edited by _Kurt

Awaiting Diablo III..

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Where are my credits? ;)

Edited by AzKay

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Like what the example script does, it (ClipGets) the highlighted text and puts the text in the input and clicks "Translate" on http://babelfish.altavista.digital.com/tr?...ext&trtext=

It returns the translated text.

Shouldnt have to "click" anything. The .Open does it all.

Edited by AzKay

# MY LOVE FOR YOU... IS LIKE A TRUCK- #

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