Tagui – Count() function not working

  • Tagui – Count() function not working

     wwlim updated 1 month ago 2 Members · 3 Posts
  • wwlim

    Member
    August 18, 2022 at 12:07 am

    Hi All,

    I have been trying to use the count row function but it does not work. Always giving me 0. So for example I just want to count the number of rows in the WSJ table website but it does not work:

    dump Index,Price to C:\Users\Wei Wen\Desktop\IndexPrices.csv

    https://www.wsj.com/market-data/stocks

    rows=count(‘//*[@id=”root”]/div/div/div/div[2]/div[4]/div/div[1]/div[3]/div/div[1]/div/table/tbody/tr’)

    echo rows

    for n from 1 to rows

    {

    read //*[@id=”root”]/div/div/div/div[2]/div[4]/div/div[1]/div[3]/div/div[1]/div/table/tbody/tr[n]/td[1] to Index

    echo Index

    read //*[@id=”root”]/div/div/div/div[2]/div[4]/div/div[1]/div[3]/div/div[1]/div/table/tbody/tr[n]/td[2] to Price

    echo Price

    news = [Index,Price]

    write csv_row(news) to C:\Users\Wei Wen\Desktop\IndexPrices.csv

    }

    Please kindly advise. thank you

  • ruthtxh

    Organizer
    August 18, 2022 at 1:10 pm

    Hi @wwlim

    seems like the tables take some time to load, hence at the start it returns 0. You can either add an explicit wait for a few seconds before you count or do a loop to to keep checking if the element is present and wait.

    The following code returned me a count of 10:

    https://www.wsj.com/market-data/stocks

    wait 5

    rows=count(‘//*[@id=”root”]/div/div/div/div[2]/div[4]/div/div[1]/div[3]/div/div[1]/div/table/tbody/tr’)

    echo rows

  • wwlim

    Member
    August 24, 2022 at 2:58 pm

    thank you so much Ruth! it works now. although i have to set to count 20 before it can work. maybe my machine loads the tables too slowly.

Viewing 1 - 3 of 3 replies