Step-by-step tutorials for you to get started with web scrapingDownload Octoparse
Scrape product data from FlipkartWednesday, December 4, 2019
The latest version for this tutorial is available here. Go to have a check now!
In this tutorial, we are going to show you how to scrape product data from Flipkart.com.
To follow through, you may want to use this URL in the tutorial:
We are going to enter each detail page and scrape the product title, rating, and price.
This tutorial will also cover:
· Deal with AJAX for pagination
· Modify XPath for accurately locating the desired price data
Here are the main steps in this tutorial: [Download task file here]
1) Go to Web page - to open the targeted web page
· Click "+ Task" to start a new task with Advanced Mode
Advanced Mode is a highly flexible and powerful web scraping mode. For people who want to scrape from websites with complex structures, like Walmart.com, we strongly recommend Advanced Mode to start your data extraction project.
· Paste the URL into the "Extraction URL" box and click "Save URL" to move on
2) Create a pagination loop - to scrape all the results from multiple pages
· Turn on the “Workflow Mode” by switching the "Workflow" button in the top-right corner in Octoparse
We strongly suggest you turn on the "Workflow Mode" to get a better picture of what you are doing with your task, just in case you mess up with the steps.
· Click the "Next" button
· Click "Loop click next page" from the "Action Tips"
· Set up AJAX Load for the "Click to paginate" action
Flipkart.com applies the AJAX technique to the pagination button. Therefore, we need to set up AJAX Load in the "Click to paginate" step.
· Uncheck the box for "Retry when page remains unchanged (use discreetly for AJAX loading)"
· Check the box for "Load the page with AJAX" and set up AJAX Timeout (2-4 seconds will work usually)
· Click "OK" to save
For more about dealing with AJAX in Octoparse：
3) Create a "Loop Item" - to loop click into each item on each list
· Click "Go To Web Page" to go back to the first page
When extracting data throughout multiple pages, you should always begin your task building on the first page.
· Make Octoparse identify and select all 24 links on the page
· Click the first product titles and click "A" tag from the "Action Tips"
· Click the second product titles and click "A" tag from the "Action Tips"
In HTML source code, the "A" tag defines a hyperlink, which is used to link from one page to another. By clicking the "A" tag on the "Action Tips", we can help Octoparse select the link to the detail page.
Normally, you don't need to click "A" manually since Octoparse will automatically distinguish and select hyperlinks. But if Octoparse fails to distinguish hyperlinks, you’ll need to select the "A" tag on your own to help Octoparse distinguish and select the link.
The selected links will be highlighted in green while other links to the detail pages will be highlighted in red. If certain links on the list page are still missing after the first two clicks, keep clicking on more links from the same list until all links desired are selected and highlighted in green.
· Click "Loop click each element" to create a "Loop Item"
Octoparse will click through each link captured in the "Loop Item", and open the detail page.
4) Extract data - to select the data for extraction
After you click "Loop click each element", Octoparse will open the detail page of the first product.
· Click on the data you need on the page
· Select "Extract text of the selected element" from the "Action Tips"
· Rename the fields by selecting from the pre-defined list or inputting on your own
As some products have more than one price, you may want to modify the XPath to locate the price data accurately on all product pages. See how it's done in Step 5.
5) Customize the data field by modifying XPath - to improve the accuracy of a certain data field (Optional)
· Select the "Price" field
· Click "Customize data field" and select "Customize XPath"
· Enter "//div[@class="_1vC4OE _3qQ9m1"]" into the "Matching XPath" box
· Click "OK" to save
For more about modifying XPath in Octoparse:
6) Start extraction - to run the task and get data
· Click “Start Extraction” on the upper left side
· Select “Local Extraction” to run the task on your computer, or select “Cloud Extraction” to run the task in the Cloud (for premium users only)
Here is the sample output.
Was this article helpful? Feel free to let us know if you have any question or need our assistance.
Contact us here !
- Most popular tutorials
- Use lists to extract
- Set up proxies
- Scrape data via Google Searching
- Extract data from source code
- How to export extracted data to a database?