🧑⚖️ What is Data Scraping?
Data scraping is the process of automatically extracting structured data from websites. It is commonly used for collecting real-time content, price comparisons, news feeds, or in our case—phone specifications from GSMArena.
🆕 Is it Legal to Scrape GSMArena?
GSMArena doesn’t provide a public API, so ethical scraping means:
- Respecting their robots.txt file.
- Not overloading their servers—use delays between requests.
- Scraping only public, non-login-required data.
Check the robots.txt regularly and avoid scraping disallowed paths.
💻 Project Technology
- Language: C#
- Framework: .NET0.9
- UI: WinForms
- HTTP: HttpClient
- HTML Parsing: HtmlAgilityPack 'Install-Package HtmlAgilityPack'
📒 Project Scenario
Our tool allows users to:
- Scrapper Form 'MainForm' starts up, check internet connectivity
- Input a GSMArena search criteria 'i.e Samsung | iPhone'
- Hit 'Scrap' button
- Scrape and parse phone names and links
- Display them in a DataGridView
- Optionally export data to CSV or Excel
- Leave TextBox blank, will scrap all phones and models.
🍡 Project Design
The form includes:
- TextBox: for URL input
- Button: to start scraping
- ProgressBar: for status
- DataGridView: to show phone data
📂 Folder Contents and Project structure
🔗Code Example
// Imports
using System.Net.Http;
using HtmlAgilityPack;
// Async scraping method
public async Task> ScrapeAllPhonesAsync(IProgress progress = null)
{
var phoneList = new List();
using var http = new HttpClient();
var url = "https://www.gsmarena.com/samsung-phones-9.php";
var html = await http.GetStringAsync(url);
var doc = new HtmlDocument();
doc.LoadHtml(html);
var nodes = doc.DocumentNode.SelectNodes("//div[@class='makers']//li/a");
if (nodes != null)
{
foreach (var node in nodes)
{
var name = node.InnerText.Trim();
var href = "https://www.gsmarena.com/" + node.GetAttributeValue("href", "");
phoneList.Add(new Phone { Name = name, Url = href });
progress?.Report($"Fetched: {name}");
}
}
return phoneList;
}
Note: This is a simplified version. Your full project handles errors, async UI updates, and allows exporting.
🧑💻Testing and Results
We tested with several brand URLs (e.g., Samsung, Nokia, Xiaomi). The scraper fetched all phone models correctly and displayed them in the grid. For stress testing, we added 2-second delays between requests to avoid throttling by GSMArena servers.
💪🏿Conclusion
With WinForms, HttpClient, and HtmlAgilityPack, you can build robust desktop scrapers. Just remember to always follow ethical scraping practices and respect site owners’ terms of service. GSMArena is a rich source for mobile phone data and can be leveraged for research, comparisons, or apps.
Bonus Tip: Enhance your scraper by saving data into an Access or SQLite database using ADO.NET for long-term storage and querying.
💬 Have questions or want more tutorials like this? Let me know in the comments! Don’t forget to check out my other VB.NET & C# tutorials.
🗝️link to this post: https://adonetaccess2003.blogspot.com/2025/07/gsmarena-scraper-csharp-winforms-net.html
♥ Here are some online Visual Basic lessons and courses:
No comments:
Post a Comment