Inputting various usernames and passwords (nested loops)

In some instances, you may have a list of usernames and passwords and your goal may be to input each username/password combination into the login page, extract data for that user and then continue with the next username/password combination. 

In this tutorial, we will demonstrate how you can do that using AirBnb as an example. 

 

Creating your lists

The is the format of a basic JSON list that you can use in ParseHub: 

{
  "myList":["item one","item two","item three","item four"]
}

If you want to combine two pieces of data, your list would look as follows: 

{
  "myList":[{"item1":"a1","item2":"a2"},
{"item1":"b1","item2":"b2"},
{"item1":"c1","item2":"c2"}]
}

For example, a list that combines usernames and passwords follows this format: 

{
  "myList":[{"username":"username1","password":"password1"},
{"username":"username2","password":"password2"},
{"username":"username3","password":"password3"}]
}

 

Building your project

1. Open your ParseHub client, click on "New Project" and input the URL you would like to scrape data from. For this example we will be using AirBnb. You can type https://www.airbnb.com/ into your project if you would like to follow along. Click on "Start project on this URL".

Screen_Shot_2017-08-29_at_3.47.41_PM.png

 

2. Go under the "Settings" tab on the project.

Screen_Shot_2017-08-29_at_3.48.13_PM.png

 

3. In the "Starting Value" box, add in your lists of keywords in JSON which you created in the first part of this tutorial. You will see both lists appear in the preview section at the bottom of ParseHub:

Screen_Shot_2017-08-29_at_3.58.12_PM.png

 

4. Go back to the "Commands" tab on your project. Then click on the "+" button next to "Select page" and click on the "Advanced" arrow to show more tools.

Screen_Shot_2017-08-29_at_4.00.17_PM.png

 

5. Choose the "Loop" command. The loop command iterates through a list, and is good for repeating commands multiple times.

Screen_Shot_2017-08-29_at_4.01.09_PM.png

 

6. In the text boxes - change "item" to "login" and type in "loginList" in the list text box (without the quotation marks).

  • You can change "item" to anything you want. The item represents one username and password set in your list of usernames and passwords.
  • Make sure the the list name is exactly the same as your list name in JSON. If you typed in {"loginList":....} make sure to keep the text in the text box as loginList (this is case sensitive).

Screen_Shot_2017-08-29_at_4.02.34_PM.png

 

7. Click on the "+" button next to "For each login in LoginList", click on the "Advanced" arrow to show all the commands and select a "Begin New Entry" command. Using this command, the results for each one of the username and password sets will go into a separate row in Excel and a separate scope in JSON. If you don't use this command anywhere in your project, the results scraped for each username and password set will over-ride one another.

Screen_Shot_2017-08-29_at_4.03.39_PM.png

 

8. Rename the "list1" name that appears next to "Begin new entry" to something else like "logins". Make sure not to name the list command the same as the list that holds your username and password sets. The list command should have a unique name.  

Screen_Shot_2017-08-29_at_4.05.54_PM.png

 

9. Now, we need to train ParseHub to click on the Login button to bring up the login pop-up. Click on the "+" button next to "Begin new entry in logins" (or "Begin new entry in list1" if you did not rename it step 8) and choose a Select command.

Screen_Shot_2017-08-29_at_4.07.45_PM.png

 

10. Use your Select command to select the Login button, which will be highlighted in green. You can optionally rename your selection1 to "loginButton" by double-clicking on "selection1" and typing in the new name.

Screen_Shot_2017-08-29_at_4.10.23_PM.png

 

11. Click on the "+" button next to "Select & Extract loginButton" (or "Select & Extract selection1" if you didn't rename your selection in the previous step) and choose a Click command

Screen_Shot_2017-08-29_at_4.12.54_PM.png

 

12. The Click command will bring up a pop-up which will ask you what action you want to take once you've clicked on this element. From the options provided, we will choose the "Create New Template" option and input a name such as "login page" since AirBnb redirects us to a new www.airbnb.com/login URL. Click on "Create New Template".

Screen_Shot_2017-08-29_at_4.15.52_PM.png

 

13. By default, ParseHub will automatically skip a page if it has already been visited previously. Because we are going to visit www.airbnb.com/login each time we want to input a different username/password set, we should click on the template's "Options" and deselect "No Duplicates".

Screen_Shot_2017-08-29_at_4.50.11_PM.png

 

14. In the new template you'll already have a Select command ready for you by default (which should say "Empty selection1"). Select the username field that appears in the login pop-up. ParseHub will automatically create an Input command for you. Instead of typing the actual username, just type in "login.username". This will tell ParseHub to add in the current username in your list of username and password sets. Also ensure that you select "expression" in the "Input type" drop-down menu so that ParseHub will read the text as an expression instead of just plain text. You can optionally rename your selection from "selection1" to "username". 

Screen_Shot_2017-08-29_at_4.34.50_PM.png

 

15. Now repeat step 13 for the password field: click on the "+" button next to "Select page" and choose a Select command. Select the password field that appears in the login pop-up. ParseHub will automatically create an Input command for you. Instead of typing the actual password, just type in "login.password". This will tell ParseHub to add in the current password in your list of username and password sets. Also ensure that you select "expression" in the "Input type" drop-down menu so that ParseHub will read the text as an expression instead of just plain text. You can optionally rename your selection from "selection2" to "password".

Screen_Shot_2017-08-29_at_4.35.19_PM.png

 

16. To click on the "login" button, click on the "+" button next to "Select page" and choose a Select command. Select the login button. You can optionally rename your selection from "selection3" to "loginButton".

Screen_Shot_2017-08-29_at_4.35.39_PM.png

 

17. Next to "Select loginButton", click on the "+" button and choose a Click command. On the pop-up, choose the option to create a new template and call it something like "post-login". Click on "Create New Template".

Screen_Shot_2017-08-29_at_4.26.27_PM.png

 

18. On our post-login template we can teach ParseHub what data we would like to extract from the page after we've logged in.

If you are starting from a website similar to AirBnb where the login is in a pop-up, you may need to teach ParseHub to log out on your post-login template using a combination of Select commands.

However, you can also start the project directly from the login page in cases where you can just visit www.examplewebsite.com/login and this should automatically let you log into a second account without the need to log out first. 

 

If you have any questions regarding your own project, you can always contact us at hello@parsehub.com

 

Have more questions? Submit request!

0 Comments

Article is closed for comments.