Web Scraping Tutorial: Branch JudgementWednesday, March 8, 2017 2:45 AM
When should you consider using "Branch Conditions"?
Tips! If you don't know how to write an XPath, you can click mceclip1.png and select the element on the page. Octoparse would generate an XPath automatically.
6)Click the branch on the right-hand side, select "Always execute the branch"
Tips! In Octoparse, you can set the condition to one of the following:
1. 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 if the page contains specific text When selected, Octoparse will look for the designated text string within the current page.
3. Execute if the current page contains a specific element When selected, Octoparse will look for the designated element (according to the XPath filled in) within the current page.
4. Execute if the current loop contains specific text When selected, Octoparse will look for the designated text string within the current loop item.
5. Execute if the current loop contains a specific 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.
4. Drag the "Extract Data" action into the left branch
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 you want to add more conditions to classify more variations, you can click to add a "Branch Conditions" action inside the loop
2. 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.
3. 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 "Always execute the branch", Octoparse will not proceed to the branch on the right as "Always execute the branch" will always be tested "True".
4. You can leave the branch blank if no data extraction action is needed when the condition is not met.
5. 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.
6. You can use nested branch judgment to further refine the test.
Author: The Octoparse Team
For more information about Octoparse, please click here.
Sign up today.