Menu

#560 if else really missing

open
nobody
2021-04-01
2020-10-06
Anonymous
No

Originally created by: PierreBrisorgueil

I have about fifteen scrapings that run from a global point of view I observe that it really complicates my code.

Examples:

  • 1/ in a form, I have to fill a field only according to the presence of a scrap parameter
  • 2/ on a site, I have to change the currency only if required
  • 3/ do actions if an element exists?

really simple things, which become quite complicated ... I have to play with loops ...

LET test = INNER_TEXT(element) != $ ? 1 : 0
LET action = (
    FOR i in 1.. test
        ......
        RETURN true
)

It really complicates the job ...

are there other possibilities? or can we consider a feature in this sense?

The more I have experienced ferret for a year, the more I have to go to this kind of test for complicated sites and production usages

Discussion

  • Anonymous

    Anonymous - 2020-10-12

    Originally posted by: PierreBrisorgueil

    @ziflex same idea for try catch to handle exceptions :

    • For example, we work on a string, to retrieve information, sometimes the value that we want to be retrieved is optional, the scrap couldn't be stop for this exception.
    • Or we would like to test two parsing methods on the string.
    • Or we call an external API to add complementary data, we should be able to catch failed
     
  • Anonymous

    Anonymous - 2020-11-11

    Originally posted by: ziflex

    I wonder if pattern matching would be better for it? We would get logical branching and keep declarative feel of the language.

     
  • Anonymous

    Anonymous - 2020-11-11

    Originally posted by: PierreBrisorgueil

    hmm, that could be a solution. But what would that give for a try-catch?

    Afterward, I am hesitant, for "if else" it would be consistent for ferret, but spontaneously when two friends tested ferret, they always asked first how to do an "if else".

    Everyone knows "if else" everywhere, even in excel. It can be interesting for "onBoarding" to have both. If I had to keep just one I think I would stay on the "if else" for that aspect.

     
  • Anonymous

    Anonymous - 2020-12-06

    Originally posted by: PierreBrisorgueil

    @ziflex Another use case, a form leads to the results page, it would be good to be able to exit the code with an if else, if a "no result" is displayed before a WAIT_ELEMENT of the results

    (one page site)

    75 lines of result treatment in this tricks to deal with it

    LET testResult = LENGTH(ELEMENTS(doc, '.no-results-heading')) == 0 ? 1 : 0
    LET actionResult = (
        FOR i in 1.. testResult
            ......
            RETURN DATA
    )
    RETURN actionResult
    
     
  • Anonymous

    Anonymous - 2021-04-01

    Originally posted by: ziflex

    Alternative solution could be adding a support of workflow - a tree of scripts that are executed within same context where you can branch the execution flow.

     

Log in to post a comment.

MongoDB Logo MongoDB