The updated tutorial for the latest version 8.1 is available here. Go to have a check now!
- Switch to the Workflow Mode by toggling the button located on the upper right-hand side
- Drag a Branch Judgement action to the inside of the loop
- Click the branch on the left-hand side, select "Execute branch when: When the current page contains element"
- Fill in the XPath for element : ".//div[@class='pb-savings']" into the text box for "Element XPath" (how to find the XPath ).
- Click "Save"
- Click the branch on the right-hand side, select "Do not judge. Always execute the branch"
- Click "Save"
In Octoparse, you can set the condition to one of the following:
1. Do not judge. Always execute the branch
When this option is selected, Octoparse will not judge at all and will proceed to execute the actions within the branch immediately. Only select this option for the branch on the right side.
2. Execute branch when current page contains text
When selected, Octoparse will look for the designated text string within the current page.
3. Execute branch when current page contains element
When selected, Octoparse will look for the designated element (according to the XPath filled in) within the current page.
4. Execute branch when current loop item contains text
When selected, Octoparse will look for the designated text string within the current loop item.
5. Execute branch when current loop item contains element
When selected, Octoparse will look for the designated element (according to the Relative XPath filled in) within the current loop item. Use this option only when you need to judge between items of a loop.
3) On the product item page (select one from the loop that has element ), click on any desired data fields to capture (learn how ). Rename the fields if needed.
4) Drag the "Extract Data" action into the branch to the left
So now, we have configured Octoparse to look for the element on the page. If the element is found, capture the desired data, otherwise, skip the product.
1. If a condition is set as "whether an element is found", the designated element must be uniquely found on the page or the judgment may fail to work.
2. Octoparse goes through the branches from left to right by default. It is important to always keep the condition you want to test for within the left branch; if the condition for the left branch is "Do not judge", Octoparse will not proceed to the branch on the right as "Do not judge" will always be tested "True".
3. You can leave the branch blank if no data extraction action is needed when the condition is not met.
4. When a data extraction action is being added to both branches, both the number of the data fields and the name of the data fields are required to be kept the same.
5. You can use nested branch judgment to further refine the test.
Artículo en español: Scraping Condición-basado
También puede leer artículos de web scraping en el website oficial