EXAMPLE: Date Inputs

This tutorial will show you how to enter a specific date range on a website in order to scrape updated results on a regular basis. This will involve using inputting javascript expressions to evaluate today's date, or a date in the future.

To follow along you can start a project for this URL: "https://www.travelocity.ca"

1. Click on the "Select page" command + button that is located on the right of the command. From the toolbox that appears, choose the "Select" tool.

2. Click on the "Flying From" input field to Select it.

3. An "Input" command will be created automatically. Enter the name of the target City:

4. Click on the "Select page" command + button that is located on the right of the command. From the toolbox that appears, choose the "Select" tool.

5. Click on the "Flying To" input field to Select it.

6. An "Input" command will be created automatically. Enter the name of the target City:

7. Click on the "Select page" command + button that is located on the right of the command. From the toolbox that appears, choose the "Select" tool.

8. Click on the "Departing" date field.

9. An "Input" command will be created automatically. Let's assume that we want to enter Today's date and schedule the project to run on a daily basis. This means that every day the project will be run with the date evaluating to that day's date. To be able to achieve this goal, you should enter the date in an expression format to be able to scrape the updated results without needing to modify the project. On ParseHub you can use a javascript library (DateJS) in order to enter date ranges. You can learn more about this library here

For this example, we will enter an expression that evaluates to today's date for the "Departing" date. Choose the "expression" option from the "Input" command drop down and enter: 

Date.today().toString('dd/MM/yy')

This expression will create the date in a 'dd/MM/yy' format, which the travelocity website can use. Please note the capital Ms MM for the month field. Do not use small case Ms, as that means 'minutes' in the DateJS library. Also, if you need to reorder the fields, you can edit the expression to suit your needs. 

Please note, this expression will not enter the date correctly while you are building the project. You can switch to "Browse" mode and enter the date manually. However, this javascript expression will work correctly on the test run as well as on the actual runs on our servers.