9 Replies Latest reply on Apr 26, 2012 10:03 AM by suite48

    how to filter selected web content for a field

    suite48

      Title

      how to filter selected web content for a field

      Post

      I am trying to filter specific data from an e-commerce site.  My approach so far has been to use "Insert from URL" into field A, which imports the raw html data for that record into a field.

      I now need a script that basically throws away the entire field content except for the price, which is hidden in this part of the html code: <meta itemprop="price" content="$9.99"  In this example the end result should be $9.99 or whatever the price is.

      Any tips?

      Thanks!

        • 1. Re: how to filter selected web content for a field
          philmodjunk

          This is a calculation, not a script:

          Let ( [ RawT = YourTextField ;
                    start = position ( RawT ; "price\" content=\"$" ; 1; 1 ) ;
                    end = position (RawT ; "\"" ; start ; 3 )
                  ];
                  GetAsNumber ( Middle ( RawT ; start ; end - start ) )
                 )

          • 2. Re: how to filter selected web content for a field
            suite48

            it works!  Thanks so much.

            • 3. Re: how to filter selected web content for a field
              suite48

              I've been looking everywhere how this text stripping through Let in combo with start/end works.  Would you explain a bit what you've done here?

              I have 3 other ones I need, but would like to also know in the future how to isolate and grab other data from html files:

              itemprop="ratingCount" content="12000"  [want to paste the found number 12000 in a ratingcount field]
              "itemprop="ratingValue" content="4.1" [want to paste the found number 4.1 in a ratingvalue field]
              Android:</dt><dd>2.1 and up</dd><dt> [want to paste the found text "2.1 and up" in a Androidversion field]
              Thanks!
              • 4. Re: how to filter selected web content for a field
                philmodjunk

                I suggest you look up each of these functions in help to learn more.

                Let allows you to define temporary values to be used later in a calculation. It's a useful way to break up a complex calcualtion into smaller, easier to manage pieces and can also reduce the amount of typing needed by subsituting a simpler variable for a long table::fieldname.

                Position returns a number identifying the position of the specified text in your field. The parameters after control the starting point and the occurrence number needed. Thus position (RawT ; "\"" ; start ; 3 ) starts searching through the text in RawT starting at the position in start to find the 3rd occurrence of a double quote located to the right of that starting point.

                the backslash is an escape character that enables you to insert a quotation mark inside a screen so that Filemaker does not interpret it as the end of a string expression.

                Thus, Filemaker evaluates \" as just the double quote character.

                • 5. Re: how to filter selected web content for a field
                  suite48

                  Thanks again for your excellent explanation!  

                  I now ran into a variation of the same challenge where the returns were text.  I used GetAsText instead.  I don't seem to be able to control the starting point in the text.  With the script below I got as return: "Requirements: </span>Compatible with iPhone 3GS".  It should have been "Compatible with iPhone 3GS".  

                  The script was applied to raw html text that included this text: 

                  Requirements: </span>Compatible with iPhone 3GS</p>
                   
                  This was my script: 
                  Let( [ RawT = MyTextField ;
                            start = Position ( RawT ; "Requirements: </span>" ; 1; 1 ) ;
                            end = Position (RawT ; "<" ; start ; 2 )
                          ];
                          GetAsText ( Middle ( RawT ; start ; end - start ) )
                         )


                  Any suggestions of how to control the starting point?  (I experimented with the "1" and "1" in the start phrase, but that didn't seem to hel)
                   
                  Thanks!

                   

                  • 6. Re: how to filter selected web content for a field
                    philmodjunk

                    Getastext has no effect in this calculation. (This is not a script, BTW. It's a calculation.)

                    Start is calculating the position of the "R" in "Requirements".

                    End is calculating the postion of the second "<" to be found to the right of start, which should be the position of < in </p>.

                    Middle then returns the text shown as it specifies the position of the start of "Requirements and then returns the number of characters from Requirements to 3GS.

                    Compute start as:

                    Start = Position ( RawT ; "Requirements: </span>" ; 1; 1 ) + Length ( "Requirements: </span>" )

                    compute end as

                    end = Position ( RawT ; "<" ; start ; 1 )

                    And you can leave out the GetAsText function here as it does not affect the results produced.

                    • 7. Re: how to filter selected web content for a field
                      suite48

                      Great!  Works well with the Length function added - just FYI, as long as I do GetAsText.  

                      When I do GetAsText I get: Compatible with iPhone 3GS, iPhone 4, iPhone 4S, iPod touch (4th generation), iPad 2 Wi-Fi, iPad 2 Wi-Fi + 3G, iPad (3rd generation) and iPad Wi-Fi + 4G.Requires iOS 4.0 or later.

                      When I do GetAsNumber I just get the numbers in the calculation stripped out: 344422334.4 (no matter whether the calculation result is a number or text)

                      • 8. Re: how to filter selected web content for a field
                        philmodjunk

                        Why would you use "getasnumber"?

                        I am suggesting that you use neither getastext nor getasnumber. Just remove that function call and keep the rest of your expression.

                        • 9. Re: how to filter selected web content for a field
                          suite48

                          I see; yes that works also and keeps it simple...