Runtime Entities
Counters
Counters are used for more convenient organization of calculations, for example, when you need to count iterations. There can be as many counters as you want, you just need to specify the name of the counter and initialize it. After that, you can increase or decrease its value by a given amount, and also read its current value and change the flow of logic depending on the result.
A few key points about counters:
- Counter commands can only be used in a block context.
- Counters exist in all contexts and are context-independent.
- Counters work only with integer numbers.
- Can be used to substitute data like variables and arguments.
Example of using counters:
---
config:
debug: 2
agent: Firefox
do:
- walk:
to: https://www.diggernaut.com/sandbox/meta-lang-object-en.html
do:
# initializing counter with name `page` and value 1
- counter_set:
name: page
value: 1
- walk:
repeat: 'yes'
to: https://www.diggernaut.com/sandbox/meta-lang-object-en.html?to=<%page%>
do:
- find:
path: body
do:
# incrementing counter `page` (by 1 - default)
- counter_increment:
name: page
# read value of counter to the register
- counter_get: page
# check if value of register is equal to 3, stop execution
- if:
match: 3
do:
- exit
Time | Level | Message |
---|---|---|
2017-10-21 20:24:52:954 | info | Stopped by exit command |
2017-10-21 20:24:52:946 | debug | True |
2017-10-21 20:24:52:940 | debug | Matching register value with: 3 |
2017-10-21 20:24:52:933 | debug | Set register to counter's page value: 3 |
2017-10-21 20:24:52:926 | debug | Counter page has been incremented to: 3 |
2017-10-21 20:24:52:918 | debug | Block content:
<h1>Title-1</h1> <p>Lorem ipsum dolor sit amet.</p> |
2017-10-21 20:24:52:910 | debug | Number of found blocks: 1 |
2017-10-21 20:24:52:902 | debug | Looking for: body |
2017-10-21 20:24:52:890 | debug | Page content: <html lang="en"> <head> <meta charset="UTF-8"/> <title>Diggernaut | Meta-Language | Object sample</title> </head> <body> <h1>Title-1</h1> <p>Lorem ipsum dolor sit amet.</p> </body> </html> |
2017-10-21 20:24:52:865 | debug | Referers: Referer: https://www.diggernaut.com/sandbox/meta-lang-object-en.html |
2017-10-21 20:24:52:858 | debug | Referer: https://www.diggernaut.com/sandbox/meta-lang-object-en.html |
2017-10-21 20:24:52:850 | info | Retrieving page (GET): https://www.diggernaut.com/sandbox/meta-lang-object-en.html?to=2 |
2017-10-21 20:24:52:841 | debug | False |
2017-10-21 20:24:52:833 | debug | Matching register value with: 3 |
2017-10-21 20:24:52:821 | debug | Set register to counter's page value: 2 |
2017-10-21 20:24:52:812 | debug | Counter page has been incremented to: 2 |
2017-10-21 20:24:52:804 | debug | Block content:
<h1>Title-1</h1> <p>Lorem ipsum dolor sit amet.</p> |
2017-10-21 20:24:52:796 | debug | Number of found blocks: 1 |
2017-10-21 20:24:52:788 | debug | Looking for: body |
2017-10-21 20:24:52:775 | debug | Page content: <html lang="en"> <head> <meta charset="UTF-8"/> <title>Diggernaut | Meta-Language | Object sample</title> </head> <body> <h1>Title-1</h1> <p>Lorem ipsum dolor sit amet.</p> </body> </html> |
2017-10-21 20:24:52:751 | debug | Referers: Referer: https://www.diggernaut.com/sandbox/meta-lang-object-en.html |
2017-10-21 20:24:52:740 | debug | Referer: https://www.diggernaut.com/sandbox/meta-lang-object-en.html |
2017-10-21 20:24:52:733 | info | Retrieving page (GET): https://www.diggernaut.com/sandbox/meta-lang-object-en.html?to=1 |
2017-10-21 20:24:52:726 | debug | Set counter page to value: 1 |
2017-10-21 20:24:52:713 | debug | Page content: <html lang="en"> <head> <meta charset="UTF-8"/> <title>Diggernaut | Meta-Language | Object sample</title> </head> <body> <h1>Title-1</h1> <p>Lorem ipsum dolor sit amet.</p> </body> </html> |
2017-10-21 20:24:52:454 | info | Retrieving page (GET): https://www.diggernaut.com/sandbox/meta-lang-object-en.html |
2017-10-21 20:24:52:447 | info | Starting scrape |
2017-10-21 20:24:52:434 | debug | Setting up default proxy |
2017-10-21 20:24:52:421 | debug | Setting up surf |
2017-10-21 20:24:52:394 | info | Starting digger: meta-lang-counter [1854] |