Announcement

Collapse
No announcement yet.

http request and filter for a particular sting

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • http request and filter for a particular sting

    Hi all,
    Ive hit a little snag in my project and hoping to get some ideas.
    Im looking for a way to search for a particular string in a webpage.


    lets say the piece of ascii text always starts the same like "abc-123- ###"
    where ### can be any possible combination of letters or numbers after but the length of the string is always the same.

    The basic flow would be
    -send http request to a particular website
    - search the returned page data for the piece of text starting with "abc-123"
    - copy abc-123-### to a clipcopy or textfile

    Its similar to using a web browser and hitting ctrl+f to search out for piece of text.
    The closet things i can find are the http.submit and http.download but i dont know if i can even use these functions to do what I need.

    the other idea im playing with is to possibly use the very handy web object. perhaps i could load the page into the web object first and then search out the html data inside (if thats even possible?)

    perhaps someone has an idea or tip to point me in the right direction.
    Of course any little code snippets would be very helpful but ill take whatever info i can get for now.

    Thank You

  • #2
    You could check the samples and the code in this thread. Of course, the sample code won't no longer work as the web site was changed since 2008, but the method shown how to do it, and the explanations, won't change much.

    Ulrich

    Comment


    • #3
      Thanks Ulrich
      This info was very helpful and has gotten me close to where i need to be, Which is to grab the info i need and then have it stored in a text file where i can search it.

      I am having challenges in searching out the data in the text file,
      there is a particular string of data i want to search out in the text file and simply display later in a listbox.

      My main challenge is that the data im looking for has a portion of text that is dynamically generated and also has special characters in it

      it looks something like this
      text_0_data="test-00AABBCDDEE:1429125925.182523000"

      where the bold data is always static, but the data within the quotations following it is dynamic generated.

      so is it possible to create such a search string for "text_0_data" but only copy the data within the quotation marks?

      Thanks again

      Comment


      • #4
        You should be able to use the string.find() function for this, but you need to adjust the search pattern you are looking for. If there is only one occurrence of text_0_data in the document, then it should be very easy to find. You could even use the AMS version of String.Find(), and once located you would look for the quotes, then finally extract the code you want with String.Mid(), if you prefer.

        Ulrich

        Comment


        • #5
          resolved

          hi ulrich, thanks for your help
          got it working perfect using your suggestions
          i was able to use x and y parameters as easy pointers and grab my dynamic text

          i used Y as 38 because data is always 38 characters long that i need
          x i use as the pointer for my start point and simply add the number of positions. i probably could have tried to make a more advanced filter but why if it works well.



          <code>
          AccessPointList = TextFile.ReadToString("C:\\AccessPointList.txt");

          x1 = String.Find(AccessPointList, "AccessPoint_0_token=", 1, false);
          x2 = String.Find(AccessPointList, "AccessPoint_1_token=", 1, false);

          -- shift from left to right to correct start point
          x1Total= x1 + 21;
          x2Total= x2 + 21;

          y = 38;

          r1Token = String.Mid(AccessPointList,x1Total,y);
          Input.SetText("R1",''..r1Token..'');

          r2Token = String.Mid(AccessPointList,x2Total,y);
          Input.SetText("R2",''..r2Token..'');
          </code>

          Comment


          • #6
            hello all.
            Hit another little snag.
            The above code worked for me based on the character length being 38 characters long.
            but now i need to somehow adjust it for variable string lengths that can be between 15-38 characters long

            the good news is that the string always starts the same and has the same basic format
            looks something like this

            teststring="123456789.abcdefg"

            basically its the data inside the quotations that varies in lengths and that i need to try filter out.

            Im thinking there could be a variation of the string.mid function that would allow be do this?

            Thanks

            Comment


            • #7
              Originally posted by dalygav View Post
              hello all.
              Hit another little snag.
              The above code worked for me based on the character length being 38 characters long.
              but now i need to somehow adjust it for variable string lengths that can be between 15-38 characters long

              the good news is that the string always starts the same and has the same basic format
              looks something like this

              teststring="123456789.abcdefg"

              basically its the data inside the quotations that varies in lengths and that i need to try filter out.

              Im thinking there could be a variation of the string.mid function that would allow be do this?

              Thanks
              Maybe count the strings length rather then presetting it to Y= 38 ?

              OR better still set Y to -1 this will enable it to read to end of the string?
              Plugins or Sources MokoX
              BunnyHop Here

              Comment


              • #8
                Thanks for the reply and info.

                this is one good option but unfortunately in my case I dont think it will solve the problem,

                ill elaborate,
                in my strings , the data im searching through looks more like this

                teststring1="123456789.abcdefg" teststring2="123456789.abcdefg"teststring3="123456 789.abcdefg" ........
                so there are multiple lines of data. sorry i should have included this before

                if i count the string length it will return to me the value of all the data in the entire string. which i dont want.

                if i use the -1 value for y i think will also have the same problem
                I think your idea will work if i only receive the data teststring1="123456789.abcdefg"

                The problem is that the device sending me this data i cant control the format or amount of data it i sending me.

                but the good news, its consistent in that it will send me the
                teststring1="123456789.abcdefg"
                so im thinking just being able to try filter out what is within the quotation marks of the string somehow is the way to go here.
                if what i am asking is even possible

                Comment


                • #9
                  Originally posted by dalygav View Post
                  Thanks for the reply and info.

                  this is one good option but unfortunately in my case I dont think it will solve the problem,

                  ill elaborate,
                  in my strings , the data im searching through looks more like this

                  teststring1="123456789.abcdefg" teststring2="123456789.abcdefg"teststring3="123456 789.abcdefg" ........
                  so there are multiple lines of data. sorry i should have included this before

                  if i count the string length it will return to me the value of all the data in the entire string. which i dont want.

                  if i use the -1 value for y i think will also have the same problem
                  I think your idea will work if i only receive the data teststring1="123456789.abcdefg"

                  The problem is that the device sending me this data i cant control the format or amount of data it i sending me.

                  but the good news, its consistent in that it will send me the
                  teststring1="123456789.abcdefg"
                  so im thinking just being able to try filter out what is within the quotation marks of the string somehow is the way to go here.
                  if what i am asking is even possible
                  Not really as you can start your count from =" and then stop the count at the last "
                  Plugins or Sources MokoX
                  BunnyHop Here

                  Comment


                  • #10
                    Thanks,
                    perhaps then yes this could work
                    im a little unsure of how to implement the count string strting from the =" and ending at the "

                    perhaps a modification of the the string.length option ?
                    any exmples wold be very helpful

                    Comment


                    • #11
                      Originally posted by dalygav View Post
                      Thanks,
                      perhaps then yes this could work
                      im a little unsure of how to implement the count string strting from the =" and ending at the "

                      perhaps a modification of the the string.length option ?
                      any exmples wold be very helpful

                      hi all hopefully someone can read the above and maybe has some suggestions.
                      Thanks

                      Comment


                      • #12
                        surprising things seem to have gone very quiet lately .

                        Comment


                        • #13
                          Really? It is not as you didn't receive help. I pointed you to a sample where I showed how I extracted an image URL and temperature information from a web page. The code worked for any size of file names, as well as didn't differ if the temperature had one, two or more digits. The sample code used the Lua function string.find(), which uses a pattern.

                          If you didn't want to use that Lua function, you could use AMS's own String.Find() and String.Mid() functions. You would use String.Find() to find the start of the string you wish to extract, then use it again to locate the closing quote, starting after the location where your first search found what you were looking for. With that information, it should be clear that you should use String.Mid() to extract the desired data.

                          So with all that info at your disposal, you only need to get busy. Examples for String.Find() can be found in the help file, and you will see that they are very easy to understand.

                          Ulrich
                          Last edited by Ulrich; 05-05-2015, 10:43 PM.

                          Comment

                          Working...
                          X