Advertisement
Diggernaut

Diggernaut sandbox meta-language

Nov 20th, 2016
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
YAML 6.42 KB | None | 0 0
  1. ---
  2. config:
  3.     debug: 2
  4.     agent: Firefox
  5. do:
  6. - link_add:
  7.     pool: paginator
  8.     url: https://www.diggernaut.com/sandbox/
  9. - walk:
  10.     to: links
  11.     pool: paginator
  12.     do:
  13.    # add next page of paginator to pool
  14.     - find:
  15.         path: 'div#content > ul > li.next > a'
  16.         do:
  17.         - parse:
  18.             attr: href
  19.         - normalize:
  20.             routine: url
  21.         - link_add:
  22.             pool: paginator
  23.     # get total results number
  24.     - find:
  25.         path: h4:contains('total results')
  26.         do:
  27.         - parse:
  28.             filter:
  29.            - results:\s*(\d+)
  30.         - variable_clear: number_of_results
  31.         - variable_set: number_of_results
  32.     - find:
  33.         path: 'div#search-detail > div.result-content'
  34.         do:
  35.        # --[ CLASS ]---------------------------------------------------------------------
  36.         # take name of Class
  37.         - find:
  38.             path: 'h3'
  39.             do:
  40.            - parse
  41.             - variable_clear: class_name
  42.             - variable_set: class_name
  43.         # take description of Class
  44.         - find:
  45.             path: 'div > p'
  46.             do:
  47.            - parse
  48.             - variable_clear: class_description
  49.             - variable_set: class_description
  50.         # take Class Activities
  51.         - find:
  52.             path: 'table > tbody > tr'
  53.             do:
  54.            # prepare new object
  55.             - object_new: post
  56.             # save main information
  57.             - variable_get: number_of_results
  58.             - object_field_set:
  59.                 object: post
  60.                 field: number_of_results
  61.             - variable_get: class_name
  62.             - object_field_set:
  63.                 object: post
  64.                 field: class_name
  65.             - variable_get: class_description
  66.             - object_field_set:
  67.                 object: post
  68.                 field: class_description
  69.             # activity field
  70.             - find:
  71.                 path: 'td.col2'
  72.                 do:
  73.                - parse
  74.                 - object_field_set:
  75.                     object: post
  76.                     field: activity
  77.             # date field
  78.             - find:
  79.                 path: 'td.col5'
  80.                 do:
  81.                # date from
  82.                 - parse:
  83.                     filter:
  84.                    - (\d{1,2}\/\d{1,2}\/\d{2,4})\s*-
  85.                 - normalize:
  86.                     routine: date_format
  87.                     args:
  88.                         format_in: '%m/%d/%y'
  89.                         format_out: '%Y-%m-%d'
  90.                 - object_field_set:
  91.                     object: post
  92.                     field: date_from
  93.                 # date to
  94.                 - parse:
  95.                     filter:
  96.                    - \s*-\s*(\d{1,2}\/\d{1,2}\/\d{2,4})
  97.                 - normalize:
  98.                     routine: date_format
  99.                     args:
  100.                         format_in: '%m/%d/%y'
  101.                         format_out: '%Y-%m-%d'
  102.                 - object_field_set:
  103.                     object: post
  104.                     field: date_to
  105.             # days field
  106.             - find:
  107.                 path: 'td.col7'
  108.                 do:
  109.                - parse
  110.                 - object_field_set:
  111.                     object: post
  112.                     field: days
  113.             # fees field
  114.             - find:
  115.                 path: 'td.col8'
  116.                 do:
  117.                - parse
  118.                 - object_field_set:
  119.                     object: post
  120.                     field: fees
  121.             - find:
  122.                # find a link to details page
  123.                 path: 'td.col11 > a'
  124.                 do:
  125.                 - parse:
  126.                     attr: href
  127.                 - normalize:
  128.                     routine: url
  129.                 - walk:
  130.                     to: value
  131.                     do:
  132.                    # --[ CLASS DETAILS ]-----------------------------------------------------
  133.                     # find 1-st field with gender
  134.                     - find:
  135.                         path: tr:contains('Gender')
  136.                         do:
  137.                         - parse:
  138.                             filter:
  139.                            - Gender:\s*(.*)
  140.                         - object_field_set:
  141.                             object: post
  142.                             field: gender
  143.                     # find 2-nd field with age
  144.                     - find:
  145.                         path: tr:contains('Ages')
  146.                         do:
  147.                         - parse:
  148.                             filter:
  149.                            - Ages:\s*(.*)
  150.                         - object_field_set:
  151.                             object: post
  152.                             field: ages
  153.                     # find 3-d field with address and phone
  154.                     - find:
  155.                         path: tr:contains('Dates\\Days\\Times')
  156.                         do:
  157.                         - find:
  158.                             path: 'td:nth-child(2) > table > tbody > tr > td:nth-child(4) > div'
  159.                             # taking all divs except first one
  160.                             slice: 1:-1
  161.                             # merging divs into one block
  162.                             merge: div
  163.                             do:
  164.                            # parsing for phone number by regex
  165.                             - parse:
  166.                                 filter:
  167.                                - (\(\d+\)\s*[\d-]+)
  168.                             - object_field_set:
  169.                                 object: post
  170.                                 field: phone
  171.                             # removing last div with phone number
  172.                             - node_remove: div:nth-child(3)
  173.                             # concatenate two parts of address with comma+space delimiter
  174.                             - find:
  175.                                 path: div
  176.                                 do:
  177.                                - parse
  178.                                 - object_field_set:
  179.                                     object: post
  180.                                     field: address
  181.                                     joinby: ', '
  182.                     # --[ CLASS DETAILS ]-----------------------------------------------------
  183.             - object_save:
  184.                 name: post
  185.         # --[ CLASS ]---------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement