<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Hashanranasinghe on Medium]]></title>
        <description><![CDATA[Stories by Hashanranasinghe on Medium]]></description>
        <link>https://medium.com/@hashanranasinghe98?source=rss-eda70dc03f36------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*LWr7Ncyf2Hg07c4A</url>
            <title>Stories by Hashanranasinghe on Medium</title>
            <link>https://medium.com/@hashanranasinghe98?source=rss-eda70dc03f36------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 03:34:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@hashanranasinghe98/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[The 10 Best Flutter Packages Every Beginner Should Practice]]></title>
            <link>https://medium.com/@hashanranasinghe98/the-10-best-flutter-packages-every-beginner-should-practice-cd2e23a4b9a2?source=rss-eda70dc03f36------2</link>
            <guid isPermaLink="false">https://medium.com/p/cd2e23a4b9a2</guid>
            <dc:creator><![CDATA[Hashanranasinghe]]></dc:creator>
            <pubDate>Tue, 01 Jul 2025 02:54:32 GMT</pubDate>
            <atom:updated>2025-07-01T02:54:32.027Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nvkbWPLb2ODatfFgiF0SbA.jpeg" /></figure><h3><strong>Introduction</strong></h3><p>If you’re reading this article, I know you’re just getting started with learning and practicing the Flutter framework. So, first things first,</p><p><em>What exactly is Flutter?</em></p><blockquote><strong><em>Flutter is a hybrid mobile app development framework developed by Google. It’s built using the Dart programming language, which was also developed by Google and is based on Java.</em></strong></blockquote><p><em>Now, what does “Hybrid” mean in this context?</em></p><blockquote><strong><em>It means you can use a single codebase to build applications for multiple platforms, including Android, iOS, Windows, Linux, macOS, and even the web.</em></strong></blockquote><p>However, keep in mind that as a <em>beginner</em>, <strong>you may need to configure each platform separately depending on your project’s requirements</strong>.</p><p>By now, you should have a basic understanding of what the Flutter framework is all about.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F12254544011488707697&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fbaby-kid-shouting-yes-yess-gif-12254544011488707697&amp;image=https%3A%2F%2Fmedia.tenor.com%2FqhDi2eEsxHEAAAAN%2Fbaby-kid.png&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/9175773c1e23138a7368686e4017fc67/href">https://medium.com/media/9175773c1e23138a7368686e4017fc67/href</a></iframe><p><em>Now, let’s take a look at what a Flutter package is.</em></p><p>A Flutter package is like a tool that helps you develop your application more easily. For example,</p><blockquote><strong><em>Imagine you need to develop a form in your app with text fields and buttons. Instead of designing everything from scratch, you can use a Flutter UI package. These UI packages come with predefined components that you can directly use in your app, saving you time and effort.</em></strong></blockquote><p><em>So, what’s the definition of a Flutter package?</em></p><blockquote><strong><em>A Flutter package is a collection of Dart classes, functions, and sometimes third-party dependencies that provide reusable code to implement specific features or functionality in your app.</em></strong></blockquote><p>The Flutter packages are available on <a href="https://pub.dev/"><strong>pub.dev</strong></a>, which is Flutter’s official package management system. You can browse, explore, and download all Flutter packages from this platform to use in your projects.</p><p>To use Flutter packages in your project, you need to add them under the <strong><em>dependencies</em></strong> section of the pubspec.yaml file. These are the packages that your app will use directly.</p><p>Some packages, however, are only needed during development, such as testing tools or code generators. These packages should be added under the <strong><em>dev_dependencies</em></strong> section of the pubspec.yaml file.</p><pre>name: myapp<br>description: &quot;A new Flutter project.&quot;<br><br>publish_to: &#39;none&#39; <br><br>version: 1.0.0<br><br>environment:<br>  sdk: &#39;&gt;=3.4.3 &lt;4.0.0&#39;<br><br><br>dependencies:<br>  flutter:<br>    sdk: flutter<br><br>  intl: ^0.19.0<br><br>  cupertino_icons: ^1.0.6<br>  google_fonts: ^6.2.1<br>  path_provider: ^2.1.5<br>  fluttertoast: ^8.2.8<br>  hive: ^2.2.3<br>  hive_flutter: ^1.1.0<br>  file_picker: ^10.1.2<br>  url_launcher: ^6.3.1<br><br><br>dev_dependencies:<br>  flutter_test:<br>    sdk: flutter<br><br> <br>  build_runner: ^2.4.10<br>  hive_generator: ^2.0.1<br>  flutter_launcher_icons: ^0.13.1<br><br>flutter_launcher_icons:<br>  android: &quot;launcher_icon&quot;<br>  ios: true<br>  image_path: &quot;assets/images/logo.png&quot;<br>  min_sdk_android: 21<br>flutter:<br>  generate: true <br>  uses-material-design: true<br><br>  assets:<br>    - assets/images/</pre><p>You should run the following command after adding any package to the pubspec.yaml file:</p><pre>flutter pub get</pre><p>As a beginner, you might be wondering:</p><p><em>What are the </em><strong><em>10 most important Flutter packages</em></strong><em> you should practice with?</em></p><p>Based on my experience, I believe these 10 packages are the most important for beginners. Why? Because with just these, you can build a small and interesting <strong>CRUD (Create, Read, Update, Delete)</strong> application without having to worry too much about complex state management or architectural patterns.</p><p>Now, let’s go through each package one by one.</p><h3>1. http</h3><p>The http package is one of the most popular Flutter packages because it allows developers to make HTTP requests easily and efficiently. Simply put, you can use this package to call APIs from your Flutter app.</p><p><em>But what are HTTP requests?</em></p><blockquote><strong><em>Those are the standard methods used to communicate with a backend server, such as GET, POST, PUT, DELETE, and PATCH. These requests let your app fetch data, send data, update resources, or delete them from a remote server.</em></strong></blockquote><p>You can download the <a href="https://pub.dev/packages/http"><strong><em>http package</em></strong></a> from pub.dev, Flutter’s official package management system. This package becomes especially important when you need to integrate a backend into your mobile application.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A_WKTmeBP7Y_bcv_dDBvjg.png" /></figure><p>As a beginner, you should practice using the http package.</p><p>Now, let’s look at a basic example of how to use the GET method with the http package.</p><pre>import &#39;package:http/http.dart&#39; as http;<br>import &#39;dart:convert&#39;;<br><br>class ApiService {<br>  final String baseUrl = &#39;https://jsonplaceholder.typicode.com &#39;;<br><br>  Future&lt;Map&lt;String, dynamic&gt;?&gt; getData(String endpoint) async {<br>    final Uri url = Uri.parse(&#39;$baseUrl/$endpoint&#39;);<br><br>    try {<br>      final response = await http.get(url);<br><br>      if (response.statusCode == 200) {<br>        return json.decode(response.body);<br>      } else {<br>        print(&#39;Failed to load data. Status code: ${response.statusCode}&#39;);<br>        return null;<br>      }<br>    catch (e) {<br>      // This will catch common exceptions like connection errors<br>      print(&#39;Error during GET request: $e&#39;);<br>      return null;<br>    }<br>  }<br>}</pre><h3>2. sqflite</h3><p><em>First, let’s take a look at what SQLite is.</em></p><blockquote><strong><em>SQLite is an open-source relational database. It does not require a separate server to run as compared to other databases. Instead, it stores data directly in a file, which is why it’s often referred to as an embedded database.</em></strong></blockquote><p>SQLite is the most widely used database in the world and is found in almost every connected device. Both Android and iOS rely heavily on SQLite for local data storage.</p><p>Flutter does not have a built-in mechanism to access SQLite databases. However, you can use the <a href="https://pub.dev/packages/sqflite"><strong><em>sqflite package</em></strong></a> to work with SQLite on both Android and iOS, which is well-maintained and officially recommended by the Flutter team.</p><p>If you’re new to SQLite or SQL queries, it’s a good idea to learn the basics first. You can start with any beginner-friendly <a href="https://www.w3schools.com/sql/"><strong><em>SQL tutorial</em></strong></a> to understand how databases work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wWukGGOrfUXojb8FZqYALg.png" /></figure><p>Now, let’s look at a basic example of how to initiate the database and use SQL queries with the sqflite package.</p><pre>import &#39;dart:io&#39; as io;<br>import &#39;package:path/path.dart&#39;;<br>import &#39;package:sqflite/sqflite.dart&#39;;<br>import &#39;package:path_provider/path_provider.dart&#39;;<br><br>class DatabaseHelper {<br>  static final DatabaseHelper _instance = DatabaseHelper._internal();<br><br>  factory DatabaseHelper() =&gt; _instance;<br><br>  static Database _db;<br><br>  DatabaseHelper._internal();<br><br>  Future&lt;Database&gt; get db async {<br>    if (_db != null) return _db;<br>    _db = await initDb();<br>    return _db;<br>  }<br><br>  Future&lt;Database&gt; initDb() async {<br>    io.Directory documentsDirectory = await getApplicationDocumentsDirectory();<br>    String path = join(documentsDirectory.path, &quot;todos.db&quot;);<br>    var dbTodos = await openDatabase(path, version: 1, onCreate: _onCreate);<br>    return dbTodos;<br>  }<br><br>  void _onCreate(Database db, int version) async {<br>    await db.execute(&#39;&#39;&#39;<br>      CREATE TABLE todos (<br>        id INTEGER PRIMARY KEY AUTOINCREMENT,<br>        item_name TEXT,<br>        date_created TEXT<br>      )<br>    &#39;&#39;&#39;);<br>    print(&quot;Table created&quot;);<br>  }<br><br>  //CRUD Operations<br><br>  // Insert<br>  Future&lt;int&gt; insertTodo(Todo todo) async {<br>    var dbClient = await db;<br>    int res = await dbClient.insert(&quot;todos&quot;, todo.toMap());<br>    return res;<br>  }<br><br>  // Get all<br>  Future&lt;List&lt;Todo&gt;&gt; getTodos() async {<br>    var dbClient = await db;<br>    List&lt;Map&lt;String, dynamic&gt;&gt; maps = await dbClient.query(&quot;todos&quot;);<br>    List&lt;Todo&gt; todos = [];<br>    for (int i = 0; i &lt; maps.length; i++) {<br>      todos.add(Todo.fromMap(maps[i]));<br>    }<br>    return todos;<br>  }<br><br>  // Get single todo by ID<br>  Future&lt;Todo&gt; getTodoById(int id) async {<br>    var dbClient = await db;<br>    var result = await dbClient.query(&quot;todos&quot;, where: &quot;id = ?&quot;, whereArgs: [id]);<br>    return Todo.fromMap(result.first);<br>  }<br><br>  // Update<br>  Future&lt;int&gt; updateTodo(Todo todo) async {<br>    var dbClient = await db;<br>    return await dbClient.update(&quot;todos&quot;, todo.toMap(), where: &quot;id = ?&quot;, whereArgs: [todo.id]);<br>  }<br><br>  // Delete<br>  Future&lt;int&gt; deleteTodo(int id) async {<br>    var dbClient = await db;<br>    return await dbClient.delete(&quot;todos&quot;, where: &quot;id = ?&quot;, whereArgs: [id]);<br>  }<br><br>  // Delete all<br>  Future&lt;void&gt; deleteAllTodos() async {<br>    var dbClient = await db;<br>    await dbClient.rawDelete(&quot;DELETE FROM todos&quot;);<br>  }<br><br>  // Close DB<br>  Future close() async {<br>    var dbClient = await db;<br>    return dbClient.close();<br>  }<br>}<br>class Todo {<br>  int id;<br>  String itemName;<br>  String dateCreated;<br><br>  Todo({required this.itemName, required this.dateCreated}) : id = -1;<br><br>  Todo.withId({required this.id, required this.itemName, required this.dateCreated});<br><br>  Map&lt;String, dynamic&gt; toMap() {<br>    var map = &lt;String, dynamic&gt;{};<br>    map[&quot;item_name&quot;] = itemName;<br>    map[&quot;date_created&quot;] = dateCreated;<br>    if (id != -1) {<br>      map[&quot;id&quot;] = id;<br>    }<br>    return map;<br>  }<br><br>  factory Todo.fromMap(Map&lt;String, dynamic&gt; map) {<br>    return Todo.withId(<br>      id: map[&#39;id&#39;],<br>      itemName: map[&#39;item_name&#39;],<br>      dateCreated: map[&#39;date_created&#39;],<br>    );<br>  }<br>}</pre><h3>3. hive</h3><p><a href="https://pub.dev/packages/hive"><strong><em>hive </em></strong></a>is a fast and lightweight NoSQL database that can be used to store local data in Flutter applications.</p><p>If you’re new to NoSQL, it’s a good idea to learn the basics first. You can start with any beginner-friendly <a href="https://www.geeksforgeeks.org/introduction-to-nosql/">No<strong><em>SQL tutorial</em></strong></a> to understand how databases work.</p><p>Hive stores your data in the boxes. So, we need to open a Hive box. A box is similar to a table in a traditional SQL database and stores key-value pairs. We can open the same box multiple times, returning the same box instance. However, it is good practice to open it once on application launch and get the box whenever we want to add, get, update, or delete data from it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KD9H3VHhA7XamfX8bgSH7A.png" /></figure><p>Now let’s go through the simple example.</p><p>Add these dependencies to your pubspec.yaml</p><pre>dependencies:<br>  hive: ^2.2.3<br>  hive_flutter: ^1.1.0<br><br>dev_dependencies:<br>  hive_generator: ^1.1.3<br>  build_runner: ^2.1.11</pre><p>Create Model person_model.dart</p><pre>import &#39;package:hive/hive.dart&#39;;<br><br>part &#39;person_model.g.dart&#39;;<br><br>@HiveType(typeId: 1) //typeId should be unique for each model<br>class PersonModel {<br>  @HiveField(0) //uinque id for each field<br>  String name;<br><br>  @HiveField(1)<br>  int age;<br><br>  @HiveField(2)<br>  List&lt;Person&gt; friends;<br>}</pre><p>After writing creating model, run the following command to generate <strong>TypeAdapter</strong></p><pre>dart run build_runner build</pre><p><strong>main.dart</strong></p><pre>import &#39;package:hive/hive.dart&#39;;<br><br>void main() async {<br>  await Hive.initFlutter();<br>  Hive.registerAdapter(PersonModelAdapter()); //add TypeAdapater<br>runApp(const MyApp());<br>}</pre><p><strong>CRUD Service</strong></p><pre>import &#39;package:your_app/models/person_model.dart&#39;;<br>import &#39;package:hive_flutter/hive_flutter.dart&#39;;<br><br>class Service {<br>final String  _boxName = &quot;personBox&quot;;<br><br>Future&lt;Box&lt;PersonModel&gt;&gt; get _box async =&gt;<br>      await Hive.openBox&lt;PersonModel&gt;(_boxName);<br><br>//create<br>  Future&lt;void&gt; addPerson(PersonModel personModel) async {<br>    var box = await _box;<br>    await box.add(personModel);<br>  }<br><br>//read<br>  Future&lt;List&lt;PersonModel&gt;&gt; getAllPerson() async {<br>    var box = await _box;<br>    return box.values.toList();<br>  }<br><br>//update<br>  Future&lt;void&gt; updateDeck(int index, PersonModel personModel) async { <br>    var box = await _box;<br>    await box.putAt(index, personModel);<br>  }<br><br>//delete<br>  Future&lt;void&gt; deletePerson(int index) async {<br>    var box = await _box;<br>    await box.deleteAt(index);<br>  }<br>}</pre><h3>4. flutter_secure_storage</h3><p>It’s a way for developers to store data in their applications, but it works a bit differently from other storage options. The <strong>f</strong><a href="https://pub.dev/packages/flutter_secure_storage"><strong><em>lutter_secure_storage</em></strong></a> plugin allows you to store data securely using KeyStore or EncryptedSharedPreferences on Android and KeyChain on iOS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LrwaLgWu3B3bgfQGDgNW7g.png" /></figure><p>The usage of the plugin is quite similar to the <a href="https://pub.dev/packages/shared_preferences"><strong><em>Shared Preferences</em></strong></a> plugin, with the key difference being that the data is encrypted. This article does not cover that package, but if you’re interested, you can explore it further through the following link.<br>Now let’s go through the simple example.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:flutter_secure_storage/flutter_secure_storage.dart&#39;;<br><br>Future&lt;void&gt; main() async {<br>  WidgetsFlutterBinding.ensureInitialized();<br>  <br>  FlutterSecureStorage secureStorage = const FlutterSecureStorage();<br><br>  await secureStorage.write(key: &#39;apiKey&#39;, value: &#39;value&#39;);<br><br>  print(await secureStorage.read(key: &#39;apiKey&#39;));<br>}</pre><h3>5. path_provider</h3><p><a href="https://pub.dev/packages/path_provider"><strong><em>path_provider</em></strong></a> is the Flutter package for finding commonly used locations on the filesystem. So, it is the most important package in Flutter for working with files and directories on the file system. It allows developers to easily access commonly used locations such as the temporary directory and the application documents directory, which are the locations where files are typically stored. It allows developers to easily access the external storage directory on the device, which is useful for applications that need to save large files or backup data.</p><p>For example, an application that allows users to take photos and save them to their device will need to use the Path Provider package to determine the location to save those photos. Similarly, an application that allows users to create and save documents will need to use this package to determine the location for saving the documents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ijnJ5KKPZXu9QpLeTMwHZg.png" /></figure><p>Now let’s go through the simple example.</p><pre>import &#39;package:path_provider/path_provider.dart&#39;;<br>import &#39;dart:io&#39;;<br><br>  getPathLocation() async {<br>    Directory tempDir = await getTemporaryDirectory();<br>    final temp_Path = tempDir.path;<br>    print(&quot;temp_path: $temp_Path&quot;);<br>    Directory appDir = await getApplicationDocumentsDirectory();<br>    final appPath = appDir.path;<br>    print(&quot;app_path: $appPath&quot;);<br>  }</pre><h3>6. file_picker</h3><p><a href="https://pub.dev/packages/file_picker"><strong><em>file_picker</em></strong></a> package is a powerful and versatile tool for Flutter developers who need to implement file selection functionality in their applications. This package provides a simple and customizable way to access the device’s file system, allowing users to pick <em>single</em> or <em>multiple</em> files, choose directories, and save files. The File Picker package allows users to select various types of files, such as<em> images, videos, audio files, PDFs, documents, and more</em>. It also supports extension filtering, so you can restrict the file types for users are allowed to pick.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XoXyWqjyCEEhYSrCDa9oGA.png" /></figure><p>Now let’s go through the simple example.</p><pre>import &#39;package:file_picker/file_picker.dart&#39;;<br>Future&lt;void&gt; pickFile() async {<br>  FilePickerResult? result = await FilePicker.platform.pickFiles();<br><br>  if (result != null) {<br>    PlatformFile file = result.files.first;<br>    print(file.name);<br>    print(file.bytes);<br>    print(file.size);<br>    print(file.extension);<br>    print(file.path);<br>  } else {<br>   <br>  }<br>}</pre><h3>7. url_launcher</h3><p>The <a href="https://pub.dev/packages/url_launcher"><strong><em>url_launcher</em></strong></a> is another important Flutter package that allows your applications to launch web browsers, map applications, dialer applications, mail applications, and more. The url_launcher package works by creating intents to open applications using different URL schemes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*boZdb6al4HE0CjbhvYsMkQ.png" /></figure><p>Now let’s go through the simple example.</p><pre>import &#39;package:flutter/material.dart&#39;;<br>import &#39;package:url_launcher/url_launcher.dart&#39;;<br><br>final Uri _url = Uri.parse(&#39;https://flutter.dev&#39;);<br><br>void main() =&gt; runApp(<br>      const MaterialApp(<br>        home: Material(<br>          child: Center(<br>            child: ElevatedButton(<br>              onPressed: _launchUrl,<br>              child: Text(&#39;Show Flutter homepage&#39;),<br>            ),<br>          ),<br>        ),<br>      ),<br>    );<br><br>Future&lt;void&gt; _launchUrl() async {<br>  if (!await launchUrl(_url)) {<br>    throw Exception(&#39;Could not launch $_url&#39;);<br>  }<br>}</pre><h3>8. google_fonts</h3><p>As a mobile app developer, working with fonts is the most important part of creating a visually appealing user interface. The <a href="https://pub.dev/packages/google_fonts"><strong><em>google_fonts</em></strong></a> package provides access to a wide range of fonts that can help enhance the look and feel of your application. With this package, you can easily implement and use various fonts from the Google Fonts library in your Flutter project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Olbjutt_g0mP4gpbD2n-Fw.png" /></figure><p>Now let’s go through the simple example.</p><pre>import &#39;package:google_fonts/google_fonts.dart&#39;;<br>Text(<br>  &#39;This is Google Fonts&#39;,<br>  style: GoogleFonts.lato(textStyle: Theme.of(context).textTheme.headline4),<br>),</pre><h3>9. fluttertoast</h3><p><a href="https://pub.dev/packages/fluttertoast"><strong><em>fluttertoast </em></strong></a>is commonly used for lightweight pop-up messages that appear very briefly, typically at the bottom of the screen. They’re similar to Snackbars but often simpler and disappear even faster without any user interaction required. These appear for a very short duration (usually less than 2 seconds) and vanish automatically. These are used to provide quick feedback to users about their actions within the application. For example, you might show a short confirmation message like “<strong><em>You have logged in successfully</em></strong>” or display validation errors when a form input is incorrect.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E_dOYJ-Qx30ka3gLPGjM4g.png" /></figure><p>Now let’s go through the simple example.</p><pre>import &#39;package:fluttertoast/fluttertoast.dart&#39;;<br>Fluttertoast.showToast(<br>        msg: &quot;This is Center Short Toast&quot;,<br>        toastLength: Toast.LENGTH_SHORT,<br>        gravity: ToastGravity.CENTER,<br>        timeInSecForIosWeb: 1,<br>        backgroundColor: Colors.red,<br>        textColor: Colors.white,<br>        fontSize: 16.0<br>    );</pre><h3>10. flutter_launcher_icons</h3><p>When you create a new Flutter project, it comes with the default Flutter icon. You can see it when you run your mobile application in the emulator. You have to use the unique app icon because it is crucial for branding and user recognition. This is where the <a href="https://pub.dev/packages/flutter_launcher_icons"><strong><em>flutter_launcher_icons</em></strong></a> package comes in, offering a simple and effective way to customize your app’s icon for both iOS and Android platforms.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lNNAaiVDLrkGvT_QbWRHUg.png" /></figure><p>Now let’s go through the simple example.</p><pre>dev_dependencies:<br>  flutter_launcher_icons: &quot;^0.14.4&quot;<br><br>flutter_launcher_icons:<br>  android: &quot;launcher_icon&quot;<br>  ios: true<br>  image_path: &quot;assets/icon/icon.png&quot;<br>  min_sdk_android: 21 # android min sdk min:16, default 21<br>  web:<br>    generate: true<br>    image_path: &quot;path/to/image.png&quot;<br>    background_color: &quot;#hexcode&quot;<br>    theme_color: &quot;#hexcode&quot;<br>  windows:<br>    generate: true<br>    image_path: &quot;path/to/image.png&quot;<br>    icon_size: 48 # min:48, max:256, default: 48<br>  macos:<br>    generate: true<br>    image_path: &quot;path/to/image.png&quot;</pre><pre>flutter pub get<br>dart run flutter_launcher_icons</pre><p>As a beginner learning and practicing the Flutter framework, it’s important to explore and become familiar with these essential packages as well. I hope this article has helped your Flutter journey.</p><p>Now, as we come to the end of the article, what are the Flutter packages you find most useful in your experience? Feel free to share your thoughts in the comments below!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Ftenor.com%2Fembed%2F14399094062682956935&amp;display_name=Tenor&amp;url=https%3A%2F%2Ftenor.com%2Fview%2Fthat%27s-the-end-of-the-show-adam-engvid-that%27s-a-wrap-learn-english-with-adam-gif-14399094062682956935&amp;image=https%3A%2F%2Fmedia.tenor.com%2Fx9PbwqWnZIcAAAAN%2Fthat%2527s-the-end-of-the-show-adam.png&amp;type=text%2Fhtml&amp;schema=tenor" width="600" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f0e403d33b22c550976e1658d557697/href">https://medium.com/media/4f0e403d33b22c550976e1658d557697/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cd2e23a4b9a2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Advanced Web Scraping: Extracting Data from PDFs Without Downloading]]></title>
            <link>https://medium.com/@hashanranasinghe98/advanced-web-scraping-extracting-data-from-pdfs-without-downloading-c0b866dfe401?source=rss-eda70dc03f36------2</link>
            <guid isPermaLink="false">https://medium.com/p/c0b866dfe401</guid>
            <dc:creator><![CDATA[Hashanranasinghe]]></dc:creator>
            <pubDate>Mon, 06 Jan 2025 14:29:09 GMT</pubDate>
            <atom:updated>2025-01-06T14:29:09.577Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Nxz0gWHMRHjsUukVXh4NOg.png" /></figure><h3>Table of contents</h3><ol><li>Introduction</li><li>Key Components of the Code</li><li>Code Snippet: Extracting Text from PDF URL</li><li>Benefits of This Approach</li><li>Conclusion</li></ol><h4><strong>1. Introduction</strong></h4><p>In my <a href="https://medium.com/@hashanranasinghe98/basic-guide-to-web-scraping-with-python-ba192616b423">previous article</a>, I covered the basics of web scraping with Python. Now, let’s explore a more advanced technique: extracting data from PDFs embedded in websites without downloading them. This method is particularly useful when dealing with frequently updated financial reports or other documents regularly published online.</p><p>Many websites, especially in the financial sector, publish important data in PDF format. Traditionally, scraping this data would involve downloading each PDF, which can be time-consuming and storage-intensive. Our goal is to extract the necessary information directly from the PDFs without saving them locally.</p><p>We’ll use a combination of Python libraries to achieve this:</p><ul><li><strong>Selenium</strong>: For navigating web pages and handling dynamic content</li><li><strong>BeautifulSoup</strong>: For parsing HTML and extracting relevant elements</li><li><strong>Requests</strong>: For fetching PDF content from URLs</li><li><strong>pdfplumber</strong>: For extracting text from PDF content</li></ul><h4>2. Key Components of the Code</h4><p>Let’s break down the main parts of our scraping script:</p><ol><li><strong>Setting up the WebDriver</strong>:<br> We use Selenium’s WebDriver to navigate to the target website and interact with its elements.</li><li><strong>Locating PDF Links</strong>:<br> We use BeautifulSoup to parse the page’s HTML and find links to PDF documents.</li><li><strong>Extracting PDF Content</strong>:<br> Instead of downloading the PDFs, we use the requests library to fetch the PDF content and pdfplumber to extract text from this content in memory.</li><li><strong>Data Extraction and Processing</strong>:<br> We use regular expressions to extract specific data points from the PDF text.</li><li><strong>Data Storage</strong>:<br> Finally, we store the extracted data in a pandas DataFrame and save it as a CSV file.</li></ol><h4>3. Code Snippet: Extracting Text from PDF URL</h4><p><strong>Importing Required Libraries</strong></p><pre>import re<br>import time<br>from io import BytesIO<br>from typing import Dict<br><br>import requests<br>import pdfplumber<br>import pandas as pd<br>from bs4 import BeautifulSoup<br>from selenium import webdriver<br>from selenium.webdriver.chrome.service import Service<br>from selenium.webdriver.support.ui import WebDriverWait</pre><p><strong>Setting Up WebDriver</strong></p><pre>service = Service(&#39;/Your_path/webdriver/chromedriver&#39;)<br>driver = webdriver.Chrome(service=Service())<br>wait = WebDriverWait(driver, 10)</pre><p><strong>Defining URL and Class Names</strong></p><pre>search_url = &#39;https://www.cse.lk/pages/cse-daily/cse-daily.component.html&#39;<br><br>report_list_class_name = &#39;rules-flexible&#39;<br>report_class_name = &#39;rules-block flexible&#39;<br>date_class_name = &#39;date&#39;<br>button_class_name = &#39;dropdown-button&#39;</pre><p><strong>Define regular expression patterns</strong></p><pre>all_share_price_index_pattern=r&#39;\((ASPI)\)\s+([\d,]+\.\d+)\s+([\d,]+\.\d+)&#39;<br>sp_sri_lanka_20_index_pattern= r&#39;(S&amp;P Sri Lanka 20 Index)\s+([\d,]+\.\d+)\s+([\d,]+\.\d+)&#39;</pre><p><strong>Extracting PDF Text</strong></p><p>This function fetches a PDF from a given URL and extracts text from its first page using pdfplumber.</p><pre>def extract_pdf_text_from_url(https://medium.com/pdf_url):<br>    headers = {<br>        &#39;User-Agent&#39;: &#39;Mozilla/5.0&#39;,<br>        &#39;Accept&#39;: &#39;application/pdf,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&#39;<br>    }<br>    response = requests.get(pdf_url, headers=headers)<br>    response.raise_for_status()<br>    <br>    with pdfplumber.open(BytesIO(response.content)) as pdf:<br>        if len(pdf.pages) &gt; 0:<br>            first_page_text = pdf.pages[0].extract_text()<br>        else:<br>            first_page_text = &quot;No pages found in PDF.&quot;<br>    <br>    return first_page_text</pre><p><strong>Extracting Data from PDF Text</strong></p><p>The extract_pdf_data function enhances web scraping capabilities by extracting specific financial information from PDF reports. Key features include:</p><ol><li>Input processing: Accepts and cleans text from PDFs</li><li>Pattern matching: Uses regex to find ASPI and S&amp;P Sri Lanka 20 Index data</li><li>Data extraction: Retrieves ‘Today’ and ‘Previous’ values for each index</li><li>Structured output: Stores data in a nested dictionary</li></ol><p>By integrating this function into the scraping script, PDF reports can be automatically processed, extracting relevant financial information efficiently and accurately.</p><pre>def extract_pdf_data(text: str) -&gt; Dict[str, Dict[str, str]]:<br>    # Clean the text by removing extra spaces and newlines<br>    text = &#39; &#39;.join(text.split())<br>    <br>    # Initialize result dictionary<br>    extracted_data = {}<br>    <br>    # Extract ASPI values<br>    aspi_match = re.search(all_share_price_index_pattern, text)<br>    if aspi_match:<br>        extracted_data[&#39;ASPI&#39;] = {<br>            &#39;Today&#39;: aspi_match.group(2),<br>            &#39;Previous&#39;: aspi_match.group(3)<br>        }<br>    <br>    # Extract S&amp;P Sri Lanka 20 Index values<br>    sp_sri_lanka_match = re.search(sp_sri_lanka_20_index_pattern, text)<br>    if sp_sri_lanka_match:<br>        extracted_data[&#39;S&amp;P Sri Lanka 20 Index&#39;] = {<br>            &#39;Today&#39;: sp_sri_lanka_match.group(2),<br>            &#39;Previous&#39;: sp_sri_lanka_match.group(3)<br>        }<br>    <br>    return extracted_data</pre><p><strong>Main Scraping Loop</strong></p><p>This loop navigates through the webpage, finds PDF links, opens them in new tabs, extracts data, and stores it in the reports list.</p><pre>reports = []<br><br>while True:<br>    # Get the HTML content of the page<br>    content = driver.page_source<br>    soup = BeautifulSoup(content, &#39;html.parser&#39;)<br><br>    # Find the main element containing the list of reports<br>    shows_element = soup.find(&#39;div&#39;, attrs={&#39;class&#39;: report_list_class_name})<br>    div_elements = shows_element.findAll(&#39;div&#39;, attrs={&#39;class&#39;: report_class_name})<br>    print(f&quot;Number of shows found: {len(div_elements)}&quot;)<br>    <br>    for div in div_elements:<br>        date_element = div.find(&#39;div&#39;, attrs={&#39;class&#39;: date_class_name})<br>        print(date_element.text)    <br>        download_button = div.find(&#39;a&#39;, attrs={&#39;class&#39;: button_class_name})<br>        href = download_button[&#39;href&#39;]<br>        driver.execute_script(f&quot;window.open(&#39;{href}&#39;, &#39;_blank&#39;);&quot;)<br>        <br>        <br>        time.sleep(10)<br>        <br>        driver.switch_to.window(driver.window_handles[1])<br>        pdf_url = driver.current_url<br>        <br>        text = extract_pdf_text_from_url(https://medium.com/pdf_url)<br>        <br>        result=extract_pdf_data(text)<br>        <br>        # Close the PDF tab and switch back to main tab<br>        driver.close()<br>        driver.switch_to.window(driver.window_handles[0])<br>        data = {<br>            &#39;date&#39;: date_element.text,<br>            &#39;pdf_url&#39;: pdf_url,<br>            &#39;extracted_data&#39;: result<br>        }<br>        reports.append(data)<br>        <br>    # Close the main tab<br>    driver.close()<br>    <br>    <br>    break<br><br>print(reports)</pre><p><strong>Saving Data to CSV</strong></p><p>Finally, this snippet processes the extracted data, creates a pandas DataFrame, and saves it to a CSV file.</p><pre># Prepare data for DataFrame<br>data_for_df = [<br>    {<br>        &#39;Date&#39;: entry[&#39;date&#39;].strip(),<br>        &#39;PDF URL&#39;: entry[&#39;pdf_url&#39;],<br>        &#39;ASPI Today&#39;: entry[&#39;extracted_data&#39;][&#39;ASPI&#39;][&#39;Today&#39;],<br>        &#39;ASPI Previous&#39;: entry[&#39;extracted_data&#39;][&#39;ASPI&#39;][&#39;Previous&#39;],<br>        &#39;S&amp;P 20 Today&#39;: entry[&#39;extracted_data&#39;][&#39;S&amp;P Sri Lanka 20 Index&#39;][&#39;Today&#39;],<br>        &#39;S&amp;P 20 Previous&#39;: entry[&#39;extracted_data&#39;][&#39;S&amp;P Sri Lanka 20 Index&#39;][&#39;Previous&#39;],<br>    }<br>    for entry in reports<br>]<br><br># Create DataFrame<br>df = pd.DataFrame(data_for_df)<br><br># Define CSV file name<br>reports_data = &quot;reports_data.csv&quot;<br><br># Save DataFrame to CSV<br>df.to_csv(reports_data, index=False)</pre><p><strong>4. Benefits of This Approach</strong></p><ol><li><strong>Efficiency</strong>: By avoiding downloads, we save storage space and reduce processing time.</li><li><strong>Real-time Data</strong>: We can always access the most up-to-date information without managing local copies of PDFs.</li><li><strong>Scalability</strong>: This method is particularly useful when dealing with a large number of PDFs or frequently updated documents.</li></ol><p><strong>5. Conclusion</strong></p><p>This advanced web scraping technique allows us to efficiently extract data from PDFs embedded in websites without the need for downloads. You can find the complete code on <a href="https://github.com/hashanranasinghe/web-scraping/tree/main/web-pdf-scraping">GitHub</a>. It’s a powerful tool for data analysts, researchers, and developers working with online financial reports or any frequently updated PDF documents.</p><p>Remember to always respect website terms of service and practice ethical web scraping.</p><p><strong>Happy coding! </strong>😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c0b866dfe401" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Basic Guide to Web Scraping with Python]]></title>
            <link>https://medium.com/@hashanranasinghe98/basic-guide-to-web-scraping-with-python-ba192616b423?source=rss-eda70dc03f36------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba192616b423</guid>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[selenium]]></category>
            <category><![CDATA[scrape-data-from-website]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Hashanranasinghe]]></dc:creator>
            <pubDate>Wed, 17 Jul 2024 16:42:49 GMT</pubDate>
            <atom:updated>2025-01-06T09:51:12.945Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="web scraping" src="https://cdn-images-1.medium.com/max/1024/1*mWjXAGFFBGsPggnd6DP20Q.jpeg" /></figure><h3><strong>Table of content</strong></h3><ol><li>What is Web Scraping?</li><li>Legal and Ethical Considerations</li><li>Common Uses of Web Scraping</li><li>Getting Started with Web Scraping in Python</li></ol><h3>1. What is Web Scraping?</h3><p>Imagine you need information from a website. Sure, you could copy it manually, but what if you need a large amount of data? That’s where web scraping comes in. Web scraping is like sending in an automated robot to fetch all the data you need from a website quickly and efficiently. It’s the key to extracting large amounts of data in a smaller amount of time.</p><h3>2. Legal and Ethical Considerations</h3><p>Web scraping, though not explicitly illegal, operates in a legal gray area. There are no blanket laws against it, and many businesses use it responsibly to extract valuable data insights. However, it’s crucial to handle scraped data ethically and avoid harming the scraped website’s operations or violating its Terms of Service (ToS).</p><p><strong>Best Practices for Web Scraping</strong></p><p>Before diving into web scraping, consider these practical tips to ensure legal compliance and ethical usage:</p><ol><li><strong>Respect Terms of Service (ToS):</strong> Always review and adhere to a website’s ToS regarding data usage and scraping permissions.</li><li><strong>Utilize APIs When Available:</strong> Whenever possible, use APIs provided by websites for data extraction rather than scraping.</li><li><strong>Check Robots.txt:</strong> Respect the rules outlined in a website’s robots.txt file. If necessary, seek permission from the website owner before scraping data that isn’t explicitly allowed.</li></ol><p>Check the robots.txt</p><blockquote>Ex: www.example.com/robots.txt</blockquote><p>4.<strong> Verify Copyright Status:</strong> Ensure that scraped data isn’t copyrighted before using or publishing it. If you plan to publish scraped data, obtain written permission from the copyright holder.</p><p>Following these guidelines allows you to navigate web scraping responsibly and legally while leveraging data for informed decision-making.</p><h3>3. Common Uses of Web Scraping</h3><ol><li><strong>Lead Generation for Marketing</strong></li></ol><p>One of the primary uses of web scraping is generating relevant leads for businesses. For example, companies often scrape business contact details from Google Business listings to build their customer base.</p><p>2. <strong>Data Analysis</strong></p><p>Web scraping is essential for collecting and analyzing data from various sources on the internet. It enables businesses to gather valuable insights crucial for informed decision-making.</p><p>3. <strong>Academic Research</strong></p><p>In academic and scientific research, data plays a vital role. Web scraping facilitates the collection of structured data from multiple online sources, aiding researchers in their studies.</p><p>4. <strong>Training and Testing Data for Machine Learning Projects</strong></p><p>For machine learning projects, high-quality training data is very important. Web scraping allows researchers and developers to gather diverse datasets from the web, enhancing the performance and accuracy of machine learning models</p><h3>4. Getting Started with Web Scraping in Python</h3><p>We’ll explore how to scrape data from the website using Python, specifically with the help of Selenium and Beautiful Soup libraries.</p><p>We’ll walk you through scraping the top 250 TV series from the IMDb website. We’ll extract the title, show type, rating, and review count for each series. Please note that this tutorial uses IMDb data strictly for educational purposes and aims to demonstrate web scraping techniques responsibly and ethically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TzB3H4Y5o6QirXsi91qpqQ.png" /></figure><h4>Let’s start by importing the required libraries.</h4><pre>import re<br>import time<br>import pandas as pd<br><br><br>from bs4 import BeautifulSoup<br>from selenium import webdriver<br>from selenium.webdriver.common.by import By<br>from selenium.webdriver.chrome.service import Service<br>from selenium.webdriver.support.ui import WebDriverWait</pre><p><strong>re</strong>: Provides support for regular expressions in Python.</p><p><strong>time</strong>: Enables time-related functions such as pausing the execution of code.</p><p><strong>selenium:</strong> Selenium is a web testing library used to automate browser activities.</p><p><strong>BeautifulSoup:</strong> Beautiful Soup is a Python package designed for parsing HTML and XML documents. It creates parse trees, which simplify data extraction.</p><p><strong>pandas:</strong> Pandas is a powerful library for data manipulation and analysis. It allows you to extract data and store it in the desired format for further analysis.</p><h4>Let’s Set Up WebDriver</h4><p>We need to set up the web driver using Selenium to scrape the data from IMDb. This process involves downloading the <a href="https://getwebdriver.com/chromedriver#stable"><strong><em>ChromeDriver</em></strong> </a>executable and specifying its path before initializing the Chrome browser (Ensure you have the <strong><em>ChromeDriver </em></strong>executable compatible with your Chrome browser version). We’ll also set up a wait object to handle dynamic content loading.</p><pre>service = Service(&#39;/Your_path/chromedriver_linux64/chromedriver&#39;)<br>driver = webdriver.Chrome(service=Service())<br>wait = WebDriverWait(driver, 10)</pre><p>Now that we have our web driver set up, let’s define the URL for the IMDb Top 250 TV series and a pattern for extracting rating of the rating_text.</p><pre>rating_pattern = r&#39;\((.*?)\)&#39;<br>search_url = &#39;https://www.imdb.com/chart/toptv/?ref_=nv_tvv_250&#39;</pre><h4>Now, let’s see how to identify the class names of HTML elements.</h4><pre>ul_class_name = &#39;ipc-metadata-list ipc-metadata-list--dividers-between sc-a1e81754-0 eBRbsI compact-list-view ipc-metadata-list--base&#39;<br>li_class_name = &#39;ipc-metadata-list-summary-item sc-10233bc-0 iherUv cli-parent&#39;<br>title_class_name = &#39;ipc-title__text&#39;<br>type_class_name = &#39;sc-b189961a-3 hidKPx cli-title-type-data&#39;<br>review_class_name = &#39;ipc-rating-star--voteCount&#39;<br>rating_class_name = &#39;ipc-rating-star ipc-rating-star--base ipc-rating-star--imdb ratingGroup--imdb-rating&#39;</pre><p>First, load the website and wait for it to fully load. Once the page is completely loaded, right-click on the website and select “Inspect” to open the developer tools. From there, you can identify and select the relevant element, then note the name of its class for use in your scraping script.</p><blockquote>Class name of ul element</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MHOBm5MBkIe0t448I2ZWqQ.png" /></figure><blockquote>Class name of li element</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UzJVvMZKsGoJNJ5-HlH7lA.png" /></figure><blockquote>Class name of title element</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SgEhMPg9toSzLE5Px5A69g.png" /></figure><blockquote>Class name of type element</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j4xyYH3S3pUitpOfWlyIPQ.png" /></figure><blockquote>Class names of Rating and review</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g22rTX4_nw6BcgHan5Vqag.png" /></figure><h4>Let’s navigate to the IMDb Top 250 TV series page.</h4><p>We’ll use the get method to load the page and a sleep function to ensure the page fully loads before we start extracting data.</p><pre>driver.get(search_url)<br>time.sleep(30)</pre><h4>Let’s dive into extracting data from the list of the TV series.</h4><pre>tv_shows = []<br><br>while True:<br>   # Get the HTML content of the page<br>   content = driver.page_source<br>   soup = BeautifulSoup(content, &#39;html.parser&#39;)<br><br><br>   # Find the main element containing the list of TV shows<br>   shows_element = soup.find(&#39;ul&#39;, attrs={&#39;class&#39;: ul_class_name})<br>   li_elements = shows_element.findAll(&#39;li&#39;, attrs={&#39;class&#39;: li_class_name})<br>  <br>   print(f&quot;Number of shows found: {len(li_elements)}&quot;)<br>  <br>   # Loop through each list item to extract data<br>   for li in li_elements:<br>      <br>       # Extract the title of the show<br>       title_element = li.find(&#39;h3&#39;, attrs={&#39;class&#39;: title_class_name})<br>       title = title_element.get_text() if title_element else &#39;N/A&#39;<br><br><br>       # Extract the type of the show (e.g., TV series, miniseries)<br>       type_element = li.find(&#39;span&#39;, attrs={&#39;class&#39;: type_class_name })<br>       show_type = type_element.get_text() if type_element else &#39;N/A&#39;<br><br><br>       # Extract the review count and use regex to clean it<br>       review_count_element = li.find(&#39;span&#39;, attrs={&#39;class&#39;: review_class_name})<br>       review = review_count_element.get_text()<br>       match = re.search(pattern, review)<br>       review_count = match.group(1) if match else &#39;N/A&#39;<br><br><br>       # Extract the rating of the show<br>       rating_element = li.find(&#39;span&#39;, attrs={&#39;class&#39;: rating_class_name})<br>       rating = rating_element[&#39;aria-label&#39;] if type_element else &#39;N/A&#39;<br><br><br>       # Store the extracted data in a dictionary<br>       show_data = {<br>           &#39;title&#39;: title,<br>           &#39;show_type&#39;: show_type,<br>           &#39;rating&#39;: rating,<br>           &#39;review_count&#39;: review_count,<br>       }<br><br><br>       # Print and append the show data<br>       print(show_data)<br>       tv_shows.append(show_data)<br>  <br>   driver.close()<br>   break<br><br><br>print(&quot;Scraping completed.&quot;)</pre><ul><li>Start by creating an empty list, <strong><em>tv_shows</em></strong>, to store the extracted data.</li><li>In the <strong><em>while </em></strong>loop, fetch the HTML content of the page using <strong><em>driver.page_source</em></strong> and parse it with <strong><em>BeautifulSoup</em></strong>.</li><li>Locate the main element holding the list of TV shows using the <strong><em>ul_class_name</em></strong>. Then, find all list items (<strong><em>li_elements</em></strong>) within this element.</li><li>Extract he title, show type, rating, and review count through the <strong><em>for</em></strong> Loop.</li></ul><blockquote><strong>Title:</strong> Use the class name (<strong>title_class_name</strong>) to extract the show’s title.<br><strong>Show Type:</strong> Use the class name (<strong>type_class_name</strong>) to extract the show’s type.<br><strong>Review Count:</strong> Extract the review count using the class name (<strong>review_class_name</strong>) and clean it with a regex pattern.<br><strong> Rating:</strong> Retrieve the rating using the class name (<strong>rating_class_name</strong>).</blockquote><ul><li>Create a dictionary (<strong><em>show_data</em></strong>) for each show, and append it to the <strong><em>tv_shows</em></strong> list.</li><li>After the <strong><em>for </em></strong>loop, break the <strong><em>while </em></strong>loop and close the driver.</li><li>Finally, print a message indicating the completion of the scraping process.</li></ul><h4><strong>Saving the Extracted Data to a CSV File.</strong></h4><p>After successfully scraping the data, the next step is to save it in a structured format for further analysis. We’ll use Pandas to convert our list of dictionaries (<strong><em>tv_shows</em></strong>) into a <strong><em>DataFrame </em></strong>and then save it as a <strong><em>CSV </em></strong>file.</p><pre>pd.DataFrame(tv_shows).to_csv(&#39;movies.csv&#39;, index=False)</pre><h4>Final output</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*guXLwRBiEM1pBvvSE8jZKA.png" /></figure><p>You can find the complete code on <a href="https://github.com/hashanranasinghe/web-scraping/tree/main/web-scraping">GitHub </a>. I hope you’ve gained a wealth of information from this article. Feel free to try it out and explore the world of web scraping!</p><p>Thanks for reading. 😃</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba192616b423" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>