Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Testing data recieved from http.request

I was wondering if I could test what is being displayed on the webpage? Such as, if a certain image is displayed on a website’s homepage

Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 6,935

    I think you can get the webpage, but I’m not sure how you would identify a specific image unless you knew the name of the images being displayed.

  • @dave1707 I have the names of the images, however I don’t know the code of how to learn which of the three it is using

  • dave1707dave1707 Mod
    Posts: 6,935

    Here’s some code that will show data received from a url, in this example, google.com . You can scroll the page up or down to show more text. I don’t know if this will be helpful or not.

    displayMode(FULLSCREEN)
    
    function setup()
        font("Courier")
        textMode(CORNER)
        setup1()
        dy=0
        da=0
        hda=0
        str=""
    
        url="http://www.google.com"
    
        http.request(url,response)
    end
    
    function setup1()
        rows=44
        char=75
        if WIDTH>768 then
            rows=32
            char=100
        end
    end
    
    function response(data,status,headers)
        print("response")
        str=data
        print(string.sub(str,1,170))
        dataLen=str:len()
        print("status",status)
        print("headers")
        for a,b in pairs(headers) do
            print(a,b)
        end
    end
    
    function draw()
        background(40, 40, 50)
        if hw~=WIDTH then
            setup1()
        end
        fill(255)
        if str~="" then
            pos=1
            startCount=pos+dy
            for z=1,rows do
                str1=""
                for z1=pos+dy,pos+dy+char-1 do
                    if z1<=dataLen then
                        v=string.sub(str,z1,z1)
                        if string.byte(v)==10 then
                            v="€"
                        elseif string.byte(v)<32 or string.byte(v)>127 then
                            v="¿"
                        end
                        str1=str1..v
                        endCount=z1
                    end
                end                   
                text(str1,0,HEIGHT-50-21*z)
                pos=pos+char
            end
            header=string.format("(Start %6d)     (End %6d)     (Size%6d)",startCount,endCount,dataLen)
            text(header,150,HEIGHT-20)
        else
            text("Reading or No Data",WIDTH/2,HEIGHT/2)
       end
    end
    
    function touched(t)
        da=da+t.deltaY/21
        if da<0 then
            da=0
        elseif da>(dataLen/char)-(rows-4) then
            da=hda
        end
        dy=math.floor(da)*char
        hda=da
    end
    
  • @dave1707 , It’s going to sound stupid, but you could explain what that code is doing. I’m sorry I don’t understand, my brain is fried from trying to decipher how the programmers set up the website I am trying to test

  • dave1707dave1707 Mod
    Posts: 6,935

    @AnotherBoringUser There’s not a whole lot to explain. It does a request to the url and just displays the information coming back as text. That’s about the only thing it does. A new line character is replaced with € and any unprintable characters with ¿ .

  • @dave1707 Okay that was what was confusing me. I didn’t realize what it was doing

Sign In or Register to comment.