How to use If else command when extracting data

web-scraping

#1

Hello Everyone,
I am a non-programmer and I have a very little knowledge about coding and all. I have just started using Kantu IDE on Chrome and studied basic commands only. I am now able to extract the data only but would like it to be more dynamic like when a tag (storeText) is not available it should continue to next step and add ‘NA’ to CSV on behalf of the missing storeText. I know it can be achieved but I am unable to figure it out with If Else condition. Your HELP will be greatly appreciated.
As an example: When “link=Visual Web Automation” is not available it should add ‘NA’ instead of it to the CSV.
{
“Name”: “a9t9 sample scrape”,
“CreationDate”: “2019-5-7”,
“Commands”: [
{
“Command”: “open”,
“Target”: “https://a9t9.com/”,
“Value”: “”
},
{
“Command”: “storeText”,
“Target”: “link=Visual Web Automation”,
“Value”: “!csvLine”
},
{
“Command”: “csvSave”,
“Target”: “a9t9_scrape”,
“Value”: “”
}
]
}

Thank you in advance


#2

Search doc for !LastCommandOk or !StatusOK


#3

I did that but couldn’t understand how to implement it. I was getting an error repeatedly. If you could help how to get it worked would really be appreciated.


#4

store | true | !errorignore

Please get familiar with Kantu before posting. There is an extensive documentation and plenty of demo macros. Kantu is very easy to grasp and learning it by docs with try and error is much more fun. I know it for a fact. I did it. )) And as a matter of fact way faster than asking help for every line on forum. There are only couple of people who respond on a regular basis. Personally I love to help on anything that is not clearly written in docs. But this is rare. And one thing is strong about Kantu is documentation and most of the time developers keep an eye on it and add and correct if anything changes in Kantu. Kudos for that.


#5

I have figured it out how to use IF ELSE but couldn’t understand how to add plain text directly to CSV when a Tag is not available. Please help on the else condition.
{
“Name”: “amazonScrape”,
“CreationDate”: “2019-5-8”,
“Commands”: [
{
“Command”: “open”,
“Target”: “https://a9t9.com/”,
“Value”: “”
},
{
“Command”: “store”,
“Target”: “true”,
“Value”: “!errorignore”
},
{
“Command”: “storeText”,
“Target”: “link=Visual Web Automati”,
“Value”: “”
},
{
“Command”: “if”,
“Target”: “${!LastCommandOK}”,
“Value”: “”
},
{
“Command”: “storeText”,
“Target”: “link=Visual Web Automation”,
“Value”: “!csvLine”
},
{
“Command”: “else”,
“Target”: “”,
“Value”: “”
},
{
“Command”: “storeValue”,
“Target”: “NA”,
“Value”: “!csvLine”
},
{
“Command”: “endif”,
“Target”: “”,
“Value”: “”
},
{
“Command”: “csvSave”,
“Target”: “testscrape8”,
“Value”: “”
}
]
}


#6

I have figured it all now. Here is the code.
{
“Name”: “a9t9 sample scrape”,
“CreationDate”: “2019-5-8”,
“Commands”: [
{
“Command”: “open”,
“Target”: “https:// a9t9 .com/”,
“Value”: “”
},
{
“Command”: “store”,
“Target”: “true”,
“Value”: “!errorignore”
},
{
“Command”: “storeText”,
“Target”: “link=Visual Web Automati”,
“Value”: “”
},
{
“Command”: “if”,
“Target”: “{!LastCommandOK}", "Value": "" }, { "Command": "storeText", "Target": "link=Visual Web Automation", "Value": "!csvLine" }, { "Command": "else", "Target": "", "Value": "" }, { "Command": "store", "Target": "NA", "Value": "!csvLine" }, { "Command": "endif", "Target": "", "Value": "" }, { "Command": "storeText", "Target": "//*[@id=\"contet\"]/div[3]/div/h2[1]", "Value": "" }, { "Command": "if", "Target": "{!LastCommandOK}”,
“Value”: “”
},
{
“Command”: “storeText”,
“Target”: “//*[@id=“content”]/div[3]/div/h2[1]”,
“Value”: “!csvLine”
},
{
“Command”: “else”,
“Target”: “”,
“Value”: “”
},
{
“Command”: “store”,
“Target”: “NA”,
“Value”: “!csvLine”
},
{
“Command”: “endif”,
“Target”: “”,
“Value”: “”
},
{
“Command”: “csvSave”,
“Target”: “testscrape8”,
“Value”: “”
},
{
“Command”: “”,
“Target”: “”,
“Value”: “”
}
]
}


#7

Glad you’ve sorted it all out!
Pease use </> button to share the code.