Jump to content

[SOLVED] Formatting and Label Help


Recommended Posts

Hello, here is my code that i need help with:

What i need to do:

1. Get all results from the SAME reference w/o skipping every other line

2. Get all the links related to the defines as well to display them after the define

RESOLVED1) How can i make the source work with more than just one $item, for example, instead of just searching for "saba", if a user enters "saba time", then it should know how to handle the space.

RESOLVED2) How can i get the results to display sequentially on the page like:

- askldjfskldjfaskljfjdklasjdlfasjfd

- asdlfjaskfdjaskljfklsjfklasjfdklajklfd

- askldjfaskljfaskldjfaskljfaskljfkljfakljf

Code [updated, 6:32pm PST on 3/5/2008]:

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=google.exe
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
#include <INet.au3>
#include <GUIConstants.au3>


GUICreate("Google Search", 600, 500)

$item2 = ""
$term = GUICtrlCreateInput("Search Term", 5, 5, 190, 25)
$but = Guictrlcreatebutton("Search", 199, 5, 62)
$choices2 = GUICtrlCreateLabel("Not Found.  Did you Mean: ", 265, 10, 169, 25)
$choices = Guictrlcreatecombo("", 396, 7, 190, 25)
GUICtrlSetState($choices, $GUI_HIDE)
GUICtrlSetState($choices2, $GUI_HIDE)
$str = ""
$resultsd = GUICtrlCreateEdit($str, 0, 32,600,470,BitOR($WS_VSCROLL,$ES_READONLY))
guisetfont(12, 400)
$progress = GUICtrlCreateProgress(265, 5, 300, 25)

GUICtrlSetState($progress, $GUI_HIDE)


Func goSearch()
GUICtrlSetState($choices, $GUI_HIDE)
GUICtrlSetState($choices2, $GUI_HIDE)
GUICtrlSetState($resultsd, $GUI_HIDE)
GUICtrlSetState($progress, $GUI_SHOW)
$item = StringReplace($item2," ","+")

$source = (_INetGetSource("http://www.google.com/search?hl=en&q=define%3A+" & $item & "&btnG=Google+Search"))




for $i = 0 to 100
        guictrlsetdata($progress, $i)
        sleep(5)
        guictrlsetdata($progress, 0)
Next
GUICtrlSetState($progress, $GUI_HIDE)


if StringInStr($source, "Did you Mean", 0) = "0" Then
Else
    GUICtrlSetState($choices, $GUI_SHOW)
    GUICtrlSetState($choices2, $GUI_SHOW)
    $nOffset = 1
    $str = ""
    while 1
        $array = StringRegExp($source, 'class=p>define: <b><i>(.*?)</i>', 1, $nOffset)
        if @error = 0 Then
            $nOffset = @extended
        Else
            ExitLoop
        EndIf
        for $i = 0 to UBound($array) - 1
                guictrlsetdata($choices,  "|"& $array[$i])
        Next
WEnd
GUICtrlSetState($resultsd, $GUI_SHOW)
GUICtrlSetData($resultsd, $str)
EndIf

$nOffset = 1
$str = ""
while 1
    $array = StringRegExp($source, '<(?i)li>(.*?)<', 1, $nOffset)
    if @error = 0 Then
        $nOffset = @extended
    Else
        ExitLoop
    EndIf
    for $i = 0 to UBound($array) - 1
        
        
        $str = $str & "-" & $array[$i] & @CRLF & @CRLF
        $str = StringRegExpReplace($str, "&#(.*?);", " " )
        $str = StringRegExpReplace($str, "<(.*?)>", " " )
        $str = StringRegExpReplace($str, "</(.*?)>", " " )
        $str = StringRegExpReplace($str, "&(.*?);", " " )
    Next
WEnd
GUICtrlSetState($resultsd, $GUI_SHOW)
GUICtrlSetData($resultsd, $str)

EndFunc


GUISetState(@SW_SHOW)

While 1
    $msg = GUIGetMsg()
    Switch $msg
    
    Case $GUI_EVENT_CLOSE
        Exit
    
    Case $but
    $item2 = GUICtrlRead($term)
    call("goSearch")
    
    Case $choices
    $item2 = GUICtrlRead($choices)
    guictrlsetdata($term, $item2)
    call("goSearch")
    
EndSwitch
WEnd

Thanks!

Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

A labels not really suited for that kind of output. I changed it to a read only edit control. Try this:

#include <INet.au3>
#include <GUIConstants.au3>

GUICreate("Hello World", 600, 500)

AutoItSetOption("GUICoordMode", "0")

GUISetState(@SW_SHOW)

$item = "hard drive"
$item = StringReplace($item," ","+")

$source = (_INetGetSource("http://www.google.com/search?hl=en&q=define%3A+" & $item & "&btnG=Google+Search"))


$nOffset = 1
$str = ""
while 1
    $array = StringRegExp($source, '<(?i)li>(.*?)<(?i)br>', 1, $nOffset)
    if @error = 0 Then
        $nOffset = @extended
    Else
        ExitLoop
    EndIf
    for $i = 0 to UBound($array) - 1
        $str = $str & "-" & $array[$i] & @CRLF & @CRLF
    Next
WEnd

GUICtrlCreateEdit($str, -1, 0,600,500,BitOR($WS_VSCROLL,$ES_READONLY))

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE
Link to comment
Share on other sites

Ok, so I have changed my code, using your help, to the following. I understand now, why the edit works best for that, that was good to nkow. I see how you got it to display line by line, which is awesome.

However, if you do a search for like 'time' or 'hope', you'll see that, with the changes I have made, it skips some of the defines. For example, the define for 'hope' is:

# a specific instance of feeling hopeful; "it revived their hope of winning the pennant"

the general feeling that some desire will be fulfilled; "in spite of his troubles he never gave up hope"

# promise: grounds for feeling hopeful about the future; "there is little or no promise that he will recover"

someone (or something) on which expectations are centered; "he was their best hope for a victory"

# expect and wish; "I trust you will behave better from now on"; "I hope she understands that she cannot expect a raise"

United States comedian (born in England) who appeared in films with Bing Crosby (1903-2003)

# be optimistic; be full of hope; have hopes; "I am still hoping that all will turn out well"

one of the three Christian virtues

# intend with some possibility of fulfilment; "I hope to have finished this work by tomorrow evening

But, when you run it, only the lines with the #'s appear in the output; why is it skipping every other one?

Lastly, can i use 'StringInStr()' to pull out the link that the defines come from as well? I think it may be possible to like create 2 arrays, one with the defines, and one with the source, and then use 'StringInStr()' to search the source, AFTER the last define set and then display the link where it came from. What I mean is that, the 2nd array will search the source, and show the link after the <br>; as each set is defined as <li> to <br>; and with the changes i made below: <(?i)li>(.*?)<, it pulls from <li> to < and everything in between so i don't miss multiple defines from one source. Is that possible, or am I thinking about this wrong?

Thanks!

#include <INet.au3>
#include <GUIConstants.au3>

GUICreate("Hello World", 600, 500)

AutoItSetOption("GUICoordMode", "0")

GUISetState(@SW_SHOW)

$item = InputBox("Search", "Enter search phrase")
$item = StringReplace($item," ","+")

$source = (_INetGetSource("http://www.google.com/search?hl=en&q=define%3A+" & $item & "&btnG=Google+Search"))


$nOffset = 1
$str = ""
while 1
    $array = StringRegExp($source, '<(?i)li>(.*?)<', 1, $nOffset)
    if @error = 0 Then
        $nOffset = @extended
    Else
        ExitLoop
    EndIf
    for $i = 0 to UBound($array) - 1
        $str = $str & "-" & $array[$i] & @CRLF & @CRLF
    Next
WEnd

GUICtrlCreateEdit($str, -1, 0,600,500,BitOR($WS_VSCROLL,$ES_READONLY))

Do
    $msg = GUIGetMsg()
Until $msg = $GUI_EVENT_CLOSE

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...