A drop-down menu is a list of items that appear when clicking on a button or text selection(as the image below shows). This tutorial will show you how to select options in a drop-down menu in Octoparse.
You may need this example link to follow through:
1) Click on the drop-down menu
2) The Tips Panel will pop up, click "Loop through options in the dropdown"
3) A Loop Item has been created and added to the workflow automatically to loop through options in the drop-down menu.
4) Check if all the options we need have been included in the Loop Item
- Click on of the Loop Item for the dropdown then refer to the looped items in the list.
- Check if all the items added to the loop are desired; If not, refine the list by using XPath function: position().
Position() refers to where the option locates in the drop-down menu.
For example, in this case, the first option in the drop-down menu is "-Select-", which is not a real option but a header, and we want to remove it from the list.
So you can just add "[position()>1]" to the current XPath. By doing so, the loop item will include every single option with a position greater than 1, or we can say just to exclude the first option.
When a drop-down menu is detected and created in Octoparse, all available options will be selected by default. Besides the method of adding [position()>1] we just introduced, to modify the list by adding or removing items, there are more methods you can use with XPath function position(), like by adding [position()="x"] to the end of the XPath to include only options of certain positions, ie. position( )=1, position( )=2, etc. To learn more tricks, please refer to: How to select a specific option from drop-down list?
5) Now we are done configuring for the drop-down menus. Click on the confirmation button to complete the search.
As you can see from the GIF above, when there are multiple drop-downs on the webpage and we want to loop through them. i,e. get the results of the different combinations, we can just follow the steps of looping through one drop-down menu as we introduced before, and repeat it several more times. The loop items newly built should be inside the former one, like this:
You might want to know which options in the different drop-down menus give us back the results accordingly. You can check the tutorials below to see how to achieve it:
If you need any assistance with your data project, feel free to submit a request here to contact our support team anytime!