Whatever your project size is, we will handle it well with all the standards fulfilled! We are here to give 100% satisfaction.
For job seekers, please visit our Career Page or send your resume to hr@actowizsolutions.com
Data has become a mighty weapon that can influence the direction of this world. This can decide the subsequent actions, which need to consider increasing sales by offering products related to customers’ tastes, using Artificial Intelligence to minimize human work, and more.
This blog will show how to scrape data from a current website; the action is generally called data scraping. For that one, we would use Tokopedia, an Indonesian E-Commerce website.
The initial step to data scraping is deciding which data we wish to get. Here, we need to find shoe (sepatu) data, and this would be organized by a review (ulasan).
Let’s observe the site. This website is formed by the markup language called HTML. And we could get the data that we want by searching the HTML of a page carefully.
Initially, let’s open the Tokopedia page at https://www.tokopedia.com.
Let’s search for the shoes on a search bar. In Indonesia, shoes are known as “sepatu”, so we will use a word “sepatu” in a search bar.
However, it’s organized by the most appropriate one, therefore, let’s change it to category by a review by changing a dropdown “Urutkan” to “Ulasan”.
Let’s observe an HTML by utilizing inspect elements or point towards a product’s card.
We can observe that a card has the class called css-y5gcsw. Then within a card, we could see some data about products.
We are interested in a name, pricing, city, and image URLs of products so let’s see an HTML element of the data.
We can observe that we can have a name using css-1b6t4dn class, pricing with the css-1ksb19c class, a city using the css-1kdc32b class, and an image having a css-1c345mg class.
After identifying the HTML of this page, let’s make a script for getting data from a page.
As Tokopedia uses JavaScript Framework to build a website, we would use the browser automation library called Selenium. We could get data from HTML using the library. Indeed, you have to install a library initially, and we want a browser, also. You could follow the Selenium installation at the link and use the virtual environment of Python for the project. For a browser, we would be utilizing Firefox for the automation procedure.
After that, it’s time to make a file called scraper.py like a place for a Scraper to reside.
Let’s make a class called Scraper, which will get the responsibility of getting data from a website. Here, we make a property called driver, which will get filled with the Selenium Webdriver. A Webdriver is the class Selenium will utilize to create a session having a browser and connecting with a browser. Therefore, if a webdriver commands a browser to open any page, the page will get opened in a browser. To make a Webdriver object connected to the Firefox browser, we could call a static function Firefox() from a Webdriver class.
After that, let’s make a function called get_data() to find data from a website. For the objective here, we require to get an URL from a website. In case, we observe that website again, we could see an URL is :
Let’s create a driver command a browser to find the URL through calling the function driver.get("URL").
After that, Just make a counter for a page, which shows products and listing to place the data.
We would get data till page 10. For every page, we would make a driver command the browser for scrolling till the end of a page as the page would not load data in case, we didn’t scroll using it. When we checked the page, we found that a page has about 6500 pixels and we would scroll every 500 pixels. For every iteration, we would wait for 0.1 seconds thus we didn’t put any load together on the server.
After the repetition for scrolling, we would get a card’s element, iterator on all elements, find the name, pricing, image, and city data, and lastly put data to a datas variable.
Then, we find all data, we could go to next page through making a driver click to next page. In case, we check HTML of a page, we could find that a page button gets css-1ix4b60-unf-pagination-item class. And we could indicate which button is needed to click through using a counter variable.
And lastly, return data like a function’s return values.
For overall codes, just check this.
Now, let’s make a file called “main.py” for checking a class functionality. Just fill a file using this code.
If we run a file, we would open a Firefox browser, and a browser would automatically search as a driver instructed within our code. After that, we can observe the results from a terminal.
We could see that we found 700 product data from a shoe-searching page!!!
Then, we would try and present data in an additional format than printing in a terminal directly.
For more information, contact Actowiz Solutions now!
You can also reach for all your mobile app scraping and web scraping services requirements.
Web Scraping Product Details from Emag.ro helps e-commerce businesses collect competitor data, optimize pricing strategies, and improve product listings.
Discover how to leverage Google Maps for Store Expansion to identify high-traffic areas, analyze demographics, and find prime retail locations.
This report explores women's fashion trends and pricing strategies in luxury clothing by analyzing data extracted from Gucci's website.
This report explores mastering web scraping Zomato datasets to generate insightful visualizations and perform in-depth analysis for data-driven decisions.
Explore how data scraping optimizes ferry schedules and cruise prices, providing actionable insights for businesses to enhance offerings and pricing strategies.
This case study explores Doordash and Ubereats Restaurant Data Collection in Puerto Rico, analyzing delivery patterns, customer preferences, and market trends.
This infographic highlights the benefits of outsourcing web scraping, including cost savings, efficiency, scalability, and access to expertise.
This infographic compares web crawling, web scraping, and data extraction, explaining their differences, use cases, and key benefits.