Using http.request for google answers

hello,

is it possible to create table of the first 20 reponses ( just summary in web ) or the url ( in images )?

i’ve found this :
http://www.google.com/support/enterprise/static/gsa/docs/admin/72/gsa_doc_set/xml_reference/request_format.htm

thanks

If i use Dave1707 's code


function setup()
    http.request("https://www.google.fr/#q=bill",gotData,fail)   
end

function draw()
    background(40, 40, 50)
end

function fail(error)
    print(error)
end

function gotData(data,status,headers)
    print(data)
    print(status)
    for x,y in pairs(headers) do
        print(x,y)
    end
end

i have different answers

here is a beginning:
You’ll have to further decode the html code, pasted in tab result.
[edit] looks like i am unable to post the code below correctly: some of the html tags are interpreted by the forum…
[edit] seems ok now
[edit] no it didnt. Corrected and tested now.

function setup()
    query = "boulanger"
    USER_AGENT = "Mozilla/5.0"
    http.request("https://www.google.fr/search?q="..query, gotData,fail,{method="GET",
    useragent=USER_AGENT})   
end

function draw()
    background(40, 40, 50)
end

function fail(error)
    print(error)
end

function gotData(data,status,headers)
    print("received")
    txt = '<'
    data = data:match( txt .. 'div id="res">(.+)' )
    t = {"return true \\\".."n--".."[["}
    for txt in data:gmatch("<li(.-)</li") do
        txt = txt:match("(<a.-</a>)")
        table.insert(t,txt)
    end
    table.insert(t,"--]]")
    data = table.concat(t,"\
")
    saveProjectTab("result",data)
end


thanks but i have an error line 20 :  t = { .........
'}' expected near 'n'

j’ai enlevé la concaténation ligne 20, ca semble marcher merci :slight_smile:

and line 25 :  table.insert....
unfinished string near ')

a very good beginning
thanks a lot

i struggled to post the code, but i did not check the posted version. What is needed is to put the ‘<’ sign in the pattern. But it may work without it also

post checked and corrected

excellent
i tried to gmatch <SPAN class="st">
to write summary too